Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

12
  • 5
    \$\begingroup\$ c = ~~a-~~b should be c = ~~a+~~b. Also, you can implicitly cast to integer using |0, for example Math.random()*6|0. \$\endgroup\$
    – mellamokb
    Commented Jun 1, 2011 at 19:48
  • 7
    \$\begingroup\$ It's cheaper to coerce a string to a number with the unary plus operator. If a and b are strings, you can do +a+b to convert to number and add them. \$\endgroup\$ Commented Dec 2, 2011 at 21:38
  • 11
    \$\begingroup\$ I swear I'm going to use d- -b in my code someday... \$\endgroup\$ Commented Dec 19, 2013 at 14:21
  • 5
    \$\begingroup\$ +a+b doesn't work (at least on mine...) // a="1",b="1",+a+b // gives "11" \$\endgroup\$
    – imma
    Commented Jan 16, 2014 at 11:46
  • 3
    \$\begingroup\$ For "Use Array-Access for repeat function calls" if you're using the function more than twice on the same object, what's a bit shorter is to assign the function to a new member like a.f=a.longfunctionname;a.f(b);a.f(c);a.f(d) \$\endgroup\$ Commented Sep 11, 2014 at 14:40