It's hard to explain exactly what
return does. I personally know that it can be confusing at first.
Some of the basic things you need to know is that:
returncan only be used in a function.
This means that you can't use the word
returnif it's not inside of a function, and if you try, you'll get an error.
returndoesn't physically log anything to the console.
Meaning, if you
returnsomething, it won't show up, you have to either
console.log() the function call, or set it equal to a variable or something. You'll see this more later.
returnends a function. Once a
returncommand is reached in the function, the computer will stop reading the function, and move onto the rest of the code.
You want to use the word return at the end of a function, or in some kind of if/else statement. I can't give you a very specific example, because I'm not very good at that, but as you progress and read other people's posts as well as complete the lessons, you'll realize where it's used.
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.