I noticed a + sign preceeding a function in the bootstrap.js code and wondered what effect this has or is it just for fun?
Asked
Active
Viewed 1,542 times
10
-
2Ugh... pictures of text. Mind if I edit it to just text? – Corey Ogburn Dec 03 '13 at 18:25
-
@CoreyOgburn no need, it's a duuuuuuupe. – Evan Davis Dec 03 '13 at 18:26
-
The answer also seems to be located here: https://stackoverflow.com/questions/5827290/javascript-function-leading-bang-syntax – Corey Ogburn Dec 03 '13 at 18:26
-
the plus operator coerces the expression to its right into a number. if there is a "([args])" after the function statement, then the whole thing becomes an expression (instead of a syntax error). the function is then executed to return a value that it then attempts to coerce into a number. if that doesn't work, no error is shown, so it "works" fine. a paren is much more readable... – dandavis Dec 03 '13 at 18:37
1 Answers
10
I think it forces the parser to treat the part following the +
as an expression. You can also read Immediately-Invoked Function Expression

Community
- 1
- 1

Rahul Tripathi
- 168,305
- 31
- 280
- 331