String to Number conversion (v5)

Revision 5 of this benchmark created on


Description

I've just found out recently there are other ways to convert a String to Number in JavaScript. Other than parseInt() and/or parseFloat() functions...

Setup

var textValue = '123';

Test runner

Ready to run.

Testing in
TestOps/sec
addition
var numValue = textValue + 0;
ready
subtraction
var numValue = textValue - 0;
ready
multiplication
var numValue = textValue * 1;
ready
division
var numValue = textValue / 1;
ready
Number()
var numValue = Number(textValue);
ready
parseFloat()
var numValue = parseFloat(textValue, 10);
ready
parseInt()
var numValue = parseInt(textValue, 10);
ready
unary +
var numValue = +textValue;
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.