Skip to main content

Posts

Showing posts with the label function declaration

JavaScript Functions: Study Note For The Return Keyword

In the last post, I shared the argument note. The arguments allow the function take inputs but not send back any output value. The return keyword allows a function to send back an output value. If we use the return keyword, it means that we can capture the value that is coming back out of the function. For example: function square(x) { return x * x; } When I enter the function in the console and call square(4), it will give us a return sign "<" in front of 16. However, in the argument function, the result only print out the value. The return value is undefined. The other thing we can do with the return keyword is save it in a variable such as: var result = square(100) result So this function call square of 100 is evaluated that return 10000 which is then stored in result. Function Declaration V.S. Function Expression Function Declaration: function sayHi() { console.log ("Hello!"); } Function Expression: v...