Is
return false
the same as:
return
No, return;
is the same as return undefined;
, which is the same as having a function with no return statement at all.
Nope, one returns false
, the other undefined
.
See this JSFiddle
but if you test this without true
or false
, it will evaluate true
or false
:
function fn2(){
return;
}
if (!fn2()){
alert("not fn2"); //we hit this
}
At this JSFiddle
http://jsfiddle.net/TNybz/2/
No.
Test it in firebug console (or wherever) -
alert((function(){return;})() == false); //alerts false.
alert((function(){return false;})() == false); //alerts true.
alert((function(){return;})()); //alerts undefined
Note that if you (even implicitly) cast undefined to boolean, such as in if statement, it will evaluate to false.
Related interesting read here and here
No, I do not think so. False is usually returned to indicate that the specified action the function is supposed to do has failed. So that the calling function can check if the function succeeded.
Return is just a way to manipulate programming flow.
No.
var i = (function() { return; })();
i === undefined
which means that i == false && i == '' && i == null && i == 0 && !i
var j = (function() { return false; })();
j === false
which means that j == false && j == '' && j == null && j == 0 && !j
Weak operators in JS make it seem like the might return the same thing, but they return objects of different types.
Its undefined
console.log((function(){return ;})())
And yes in javaScript return is such a powerful stuff if used nicely in patters. You can return all the way to [] array, {} object to functions too.
Returning "this" you can go ahead and get implementation of class based objects and prototype inheritance and all.