Clone and edit this document
Runkit
Runkit
home page
user forum
new notebook
clone notebook
download notebook
support & documentation
log in
sign up
new notebook
help & feedback
clone this notebook
download this notebook
Sign In
Sign Up
parseInt and Number()
node v18.11.0
version:
1.0.0
endpoint
share
tweet
// parsing: parseInt("20px"); // 20
parseInt("10100", 2); // 20
parseInt("2e1"); // 2
parseInt(0b10100) // explicit binary 20
// type conversion Number("20px"); // NaN
Number("2e1"); // 20, exponential notation
Number("010"); // 10
Number("0o10") // 8, explicit octal
parseInt("010"); // 8, implicit octal
parseInt("010", 10); // 10, decimal radix used
// In addition, a widely used construct to perform Numeric type conversion, is the Unary + Operator (p. 72), it is equivalent to using the Number constructor as a function:
+"2e1"; // 20
+"0xF"; // 15
+"010"; // 10
Loading…
no comments
sign in
to comment