O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Converting Strings to Numbers

new Number("16");   //returns 16 new Number("0x20"); //returns 32 new Number("32.8"); //returns 32.8

To convert numerical-based strings into a number, create a new number object. JavaScript automatically detects whether the string is a number (even hex number with 0x## formatting) and create a new number object. If the string is not a valid number format, a NaN object is returned.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required