Return keyword explanation?


Can someone explain what return does? I'm having trouble understanding. Thank you!


Return is something that checks the code. Like, let's say return true in a loop. For example, if loop.

var dsx = false

if(dsx === false){
return dsx
dsx = false

Now, there's a common topic that's asked, which is "What's the difference between a console.log and return statement?"

Well, there's a big difference. What console.log does is just printing. No checking, nothing. A return statement, unlike a console.log, is able to check something in the code. It's a cool thing, confusing and all though, but it'll get easy to understand later. :blush:

Return statements, more specifically, are used to stop functions, executes them, etc. It will also return the specified value. :smiley:

For a more detailed explanation: