The basic question here is how do I know when to use and
what is the critical difference between each of them:
- The
Number.parseIntmethod (or justparseInt), Number.parseFloatmethod (or justparseFloat),Number()function (or class?),- and the
+operator
for converting JavaScript values (mostly String's) to numbers.
Especially since all of them give similar values and can convert String to its Number representation:
Number.parseInt("2") // returns 2
Number.parseFloat("2") // returns 2
Number("2") // returns 2
+"2" // returns 2
/* Plus a few more methods... */
eval("2") // returns 2
JSON.parse("2") // returns 2