10

I noticed a + sign preceeding a function in the bootstrap.js code and wondered what effect this has or is it just for fun?

twitter bootstrap

4
  • 2
    Ugh... pictures of text. Mind if I edit it to just text? Commented Dec 3, 2013 at 18:25
  • @CoreyOgburn no need, it's a duuuuuuupe. Commented Dec 3, 2013 at 18:26
  • The answer also seems to be located here: stackoverflow.com/questions/5827290/… Commented Dec 3, 2013 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... Commented Dec 3, 2013 at 18:37

1 Answer 1

10

I think it forces the parser to treat the part following the + as an expression. You can also read Immediately-Invoked Function Expression

Also check JavaScript plus sign in front of function name

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.