Quote Originally Posted by Twey View Post
If you're not sure whether you're dealing with a number or a string, be safe and convert it. There are several methods of doing this:
Code:
new Number(n);
No! That evaluates to a Number object, not a number. Whilst it should work, it will involve further conversion (through use of the valueOf method). Instead, call the constructor function as a function:

Code:
Number(n)
-n;
Just to point out the obvious: this will evaluate to a number with reversed sign.

Quote Originally Posted by djr33 View Post
Isn't the easiest way, then to do
a + 1*b; ?
There isn't really any objective answer to that, though for compactness I would use unary plus (+) and for readability, the Number constructor function:

Code:
a + (+b)
a + Number(b)
The parentheses emphasis the meaning, as well as help prevent an accident like confusing "+ +b" for "++b".

Quote Originally Posted by Twey View Post
Yes, +"3" performed an average of 0.0053ms faster than parseInt("3", 10) over 100,000 iterations in SpiderMonkey.
Unary plus should be the fastest of all techniques.