Instead of using console.log inside the getRemainder function, we used the return keyword. return will take the result of the math operation and give it back to whatever calls it.

On the last line, we called the getRemainder function inside of a console.log statement, which outputted the result of 14.

This code achieved the same output as before, however now our code is better. Why? If we wanted to use the getRemainder function in another place in our program, we could without printing the result to the console. Using return is generally a best practice when writing functions, as it makes your code more maintainable and flexible.

Report a Bug

If you see a bug or any other issue with this page, please report it here.