What does the exclamation mark do before the function in JavaScript?

JavascriptWeb DevelopmentFront End Technology

The ! symbol shows that it is an immediately-invoked function expression.

The exclamation mark won’t invoke the function alone; you can put () at the end −

!function foo() {}()

() has higher precedence than ! and instantly calls the function.

You can also mention it like the following −

(function(){})();

The ! allows the expression to return true. This is because by default all immediately-invoked function expression return undefined, so, we’re left with ! undefined, which is true.

raja
Published on 29-Jan-2018 14:27:57
Advertisements