Return keyword explanation?


#1

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


#2

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
}
else{
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:

https://www.codecademy.com/forum_questions/50107c79dcd8fd0002003498