0

Reading some third party code, a self invoking function starts with !function. What is the meaning of the exclamation mark in this context?

!function(){ // not assigned to variable or returned //code here }() 
6
  • 4
    Oops, I mean this one: stackoverflow.com/questions/3755606/… Commented Oct 8, 2017 at 15:19
  • It does a logic NOT (the !) on the result of the self invoking function. Commented Oct 8, 2017 at 15:19
  • 1
    it forces the following expression to evaluate. (but only for this case, void is the statement of choice.) Commented Oct 8, 2017 at 15:19
  • 1
    it's one character shorter than wrapping the whole function expression in parentheses before calling it. Commented Oct 8, 2017 at 15:20
  • 1
    and it also prevents the line being misinterpreted as a continuation of the previous one if there wasn't a semicolon. Lines starting with a parens can be risky so if you count the semicolon, this is TWO whole characters shorter! :D Commented Oct 8, 2017 at 15:22

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.