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)Just to point out the obvious: this will evaluate to a number with reversed sign.-n;
There isn't really any objective answer to that, though for compactness I would use unary plus (+) and for readability, the Number constructor function:
The parentheses emphasis the meaning, as well as help prevent an accident like confusing "+ +b" for "++b".Code:a + (+b) a + Number(b)
Unary plus should be the fastest of all techniques.




Reply With Quote
Bookmarks