- 1
When JavaScript reaches a return statement, the function stops executing. Please explain its full meaning.
if possible please give any example
3 ответов
+ 6
If I write program that have return the greater value for example:
var n = age(2,1)
function age(x,y){
if(x>y){
return x;
}return y;
}
that mean if x>y : this function already have return value.And it can stop the process.
Else : the function does not read if statement and it have return y next. This function is already return y and stop the process.
0
thanks sir
- 1
An analogy: when you call a function, you want it to do some actions. When the definition of the function reaches a return statement, it says "hey, the job is done, and this is the answer you asked me for".