If a number starts with a zero, it is usually considered to be in octal (base 8) notation:
047; // 4 eights and 7 units
gines implement this convention.
Numbers can also be represented in exponential notation, which is shorthand for "multiply
by 10 to the power of" (you may have heard this referred to as "scientific notation" or
"standard form"). Here are some examples:
1e6; // means 1 multiplied by 10 to the power 6 (a million)
2E3; // can also be written as 2E3, 2E+3 and 2e+3
Fractional values can be created by using a negative index value:
2.5e-3; // means 2.5 multiplied by 10 to the power -3
Numbers also have some built-in methods, although you need to be careful when using the
dot notation with number literals that are integers because the dot can be confused for a
decimal point. There are a few ways to deal with this, which we'll demonstrate with the
toExponential() method; this returns the number as a string in exponential notation.
Use two dots:
5..toExponential(); >> "5e+0"
Search WWH ::