return false the same as return?

Is

return false 

the same as:

return

Answers:

Answer

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.

Answer

No, return; is the same as return undefined;, which is the same as having a function with no return statement at all.

Answer

No. They are not the same. Returning false from a function returns the boolean false, where a void return will return undefined.

Answer

It's returning undefined it's commonly used to break execution of the following lines in the function

Answer

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/

Answer

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.

Answer

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

Answer

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.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.