+ 4

What does return means?

return

19th Sep 2016, 1:17 PM
Terry Jephtah Shemishere
Terry Jephtah Shemishere - avatar
7 Respostas
+ 4
"return"s functionality resembles a bit of "print"s. The result of return can be a string, an expression or an object, etc. (//return "hello"; //return 4+2;...) The distinguishing part of return is it executes only one time for each function call and terminates the function. I mean, if you have a code line after return, it will never be executed. Hence, you can write only one return in one function's scope ( if you have conditionals of course you can write more than one :) but only one of them will be executed and done.)
22nd Sep 2016, 3:42 AM
b t
b t - avatar
+ 3
its like an answer to a question: function isGreen(color) { //is the color's value green? if(color == "green") { //Yes ! return true; } else { return false; } } if(isGreen("green")) { alert("Amazing"); }
19th Sep 2016, 12:05 PM
Fernando
Fernando - avatar
+ 1
thank you Fernando, thank you zen
19th Sep 2016, 5:04 PM
Terry Jephtah Shemishere
Terry Jephtah Shemishere - avatar
+ 1
what is the actual your function get at the end that is return
3rd Dec 2016, 11:10 AM
SK Ali
SK Ali - avatar
0
"return" does not have to return a value. take this example. this.hello = function(x) { if (x < 10) { return; } alert("x is greater or equal to 10"); } if you pass a value lower than 10 to this function, the alert is never executed because the function returns when the return command is executed.
6th Nov 2016, 4:05 AM
Birk
Birk - avatar
0
after return the function stops
22nd Feb 2017, 10:23 PM
Bas
- 1
It returns from the function while sending back a return value.
19th Sep 2016, 8:11 AM
Zen
Zen - avatar