Any number, it’s number. String looks like a number, it’s number. Everything else, it goes NaN.
JavaScript
x
4
1
'a' => NaN
2
'1' => 1
3
1 => 1
4
Advertisement
Answer
There are 4 ways to do it as far as I know.
JavaScript
1
5
1
Number(x);
2
parseInt(x, 10);
3
parseFloat(x);
4
+x;
5
By this quick test I made, it actually depends on browsers.
Implicit
marked the fastest on 3 browsers, but it makes the code hard to read… So choose whatever you feel like it!