© Russ Ferguson and Keith Cirkel 2017

Russ Ferguson and Keith Cirkel, JavaScript Recipes, 10.1007/978-1-4302-6107-0_4

4. Working with Numbers and Math

Russ Ferguson and Keith Cirkel2

(1)Ocean, New Jersey, USA

(2)London, UK

Converting Strings to Numbers

Problem

Receive a value as a string and convert it to a number.

Caution

Methods attached to the Number object are part of ECMAScript 6 (ES6, the new standard of JavaScript). Older browsers that still in use, such as Internet Explorer 11 and below and Safari 7 and below, do not support these features (they work to the older ECMAScript 5 or ES5 standard). Check out http://kangax.github.io/es5-compat-table/es6/ for the current compatibility charts.

Solution

There are several ways to make this conversion. ...

Get JavaScript Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.