Return statement simplified

Hello, all hope you are doing well…
I was hoping someone would explain when to use the return statement and how it works. I have been stuck on this for the past 2 days so I am hoping that someone can simplify it as much as possible.
Thank you in advance:)

EDIT: Please do correct me if I am right.

function plusThree(num) {
  return num + 3;
}
var answer = plusThree(5);

In this code above :arrow_up: , the num placeholder = 5 right? that’s why if I did num(5) + 3 it equaled 8. If what I am saying is right, then is this how the return statement is supposed to work?

The return statement ends the execution of a function and tells the function what value to return. The expression to the right of the return is evaluated (if provided) and the value of that expression is returned. If no expression is provided then undefined is returned. So you would use a return statement whenever you need your function to return a value.

In your example above, yes, num would be equal to 5 because that is the value it is given when the function is called since 5 is passed into the function. The return statement in the function would then return 5 + 3, or 8. In other words, plusThree(5) returns the value 8.

You haven’t defined a function called num so num(5) won’t work.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.