Numbers
These are all JavaScript Numbers examples. No matter positive, negative or decimal. We call them numbers.
- 1
- 3.14
- -27.5
- 5000
Numberic separator(_)
If you want, you can use the numeric separator (_) to represent larger numbers more clearly.
For example,
let number = 1_000; // equivalent to 1000
It makes it easier to read larger numbers.
For example,
let number = 1_000_000; // 1000000(1 million)
Converting number to string
By using .toString()
method, numbers can be converted to strings.
For example,
let number = 15;
number.toString(); //"15"
NaN
NaN stands for Not a Number. When there is an error in the code, most commonly when you forget to convert a string to a number, NaN occurs.
For example, when multiply a number with a string.
"four" * 4; // NaN