Why two same statements are returning different results with just parentheses wrapping one and not the other one?
function foo(bar){
return !bar;
}(false) ? false : true; // returns true
(function foo(bar){
return !bar;
}(false) ? false : true); // returns false! why?!
is like saying:
your function is not called, and your condition is
false, meaning it returns the second statement (which has//true).the second is VERY different
is like this:
you are technically creating a
self-executing functionimmediately invoked function expressions (IFFE) withfalseas a parameter. whatever it returns is subject to the condition. so:falseas parametertruetrue, it executes the first statement of your condition (which has//false)self-executing functionsimmediately invoked function expressions (IFFE) commonly have these forms, and are commonly used to form closures (which is out of the scope of this question)