+ 4
What does return means?
return
7 ответов
+ 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.)
+ 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");
}
+ 1
thank you Fernando, thank you zen
+ 1
what is the actual your function get at the end that is return
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.
0
after return the function stops
- 1
It returns from the function while sending back a return value.