Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
56
rated 0 times [  60] [ 4]  / answers: 1 / hits: 15498  / 13 Years ago, thu, march 24, 2011, 12:00:00

Possible Duplicate:

What does the exclamation mark do before the function?






I saw a function formatted like this today for the first time:



!function(){}();


What is the preceding exclamation mark for? I assume it functions the same as:



(function(){})();


But... what's going on here?


More From » javascript

 Answers
281

The preceding ! takes the un-parseable statement, and allows it to to be parsed by the JS engine, which in turn returns true.



function(){}();
SyntaxError: Unexpected token (

!function(){}();
>>true

[#93088] Wednesday, March 23, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
janayr

Total Points: 80
Total Questions: 80
Total Answers: 114

Location: Venezuela
Member since Sat, Aug 22, 2020
4 Years ago
;