Search posts, tags, users, and pages
Self-Invoking function, returning a falsey value 'undefined', !falsey is true.
@peek4y , but !function(){console.log("blala")}() , consoles "blala" as well, but instead when you try to run function(){console.log("blala")}(), it gives an error. It seems that running it with a not ("!") makes it evaluate as ! eval ( function(){console.log("blala")}() ), why's that?
@gdadsriver So, how !function(){console.log('blahblah')}() gets evaluated is - !(function(){console.log('blahblah'))(); - first the function declaration, then invocation, then evaluate the falsey value.
function(){console.log('blahblah')}() - error. (basically syntax error)
but, (function(){ console.log('blahblah') })() - executes.
yeah, in that case, function(){console.log('blahblah')}() should evaluate as (function(){})(), but I'm not sure why it doesn't, I guess it's JavaScript that's why :D
@peek4y I'd like to know what in javascript am I missing that I'm not able to explain why function(){console.log("blala")}() isn't being invoked while (function(){console.log("blala")})() IIFE does
@gdadsriver TBH, I don't know the exact reason, but what I'm guessing is function(){}() is a declaration syntax, and ofcourse it's a wrong way to declare a function, and !function(){}() is an expression to be evaluated, so it evaluates each and every component of the expression in a proper order, probably that might be the reason? apart from that, honestly I've no explanation to it, sorry. :(