Skip to content

Latest commit

 

History

History
32 lines (23 loc) · 823 Bytes

2016-01-23-converting-to-number-fast-way.md

File metadata and controls

32 lines (23 loc) · 823 Bytes
layout title tip-number tip-username tip-username-profile tip-tldr redirect_from categories
post
Converting to number fast way
23
sonnyt
Converting strings to numbers is extremely common. The easiest and fastest way to achieve that would be using the + operator.
/en/converting-to-number-fast-way/
en
javascript

Converting strings to numbers is extremely common. The easiest and fastest (jsPerf) way to achieve that would be using the + (plus) operator.

var one = '1';

var numberOne = +one; // Number 1

You can also use the - (minus) operator which type-converts the value into number but also negates it.

var one = '1';

var negativeNumberOne = -one; // Number -1