Update JavaScript Datatype -- Number (#6275)

Added Definition and Easy to Understand Examples for DataType Number.
pull/6276/head
Pranjal Pratap Singh 4 months ago committed by GitHub
parent 1019addbcd
commit 3f4a256e94
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 26
      src/data/roadmaps/javascript/content/number@GZ_SXsWmP7AsXRTc4WUMw.md

@ -1 +1,25 @@
# number
# number
The `Number` data type in JavaScript represents floating-point numbers, such as 37 or -9.25. The `Number` constructor provides constants and methods to work with numbers, and values of other types can be converted to numbers using the `Number()` function.
### Example
```JS
let num1 = 255; // integer
let num2 = 255.0; // floating-point number with no fractional part
let num3 = 0xff; // hexadecimal notation
let num4 = 0b11111111; // binary notation
let num5 = 0.255e3; // exponential notation
console.log(num1 === num2); // true
console.log(num1 === num3); // true
console.log(num1 === num4); // true
console.log(num1 === num5); // true
```
In this example:
- `255` and `255.0` are equivalent, as JavaScript treats both as the same number.
- `0xff` represents `255` in hexadecimal notation.
- `0b11111111` represents `255` in binary notation.
- `0.255e3` is `255` in exponential notation.
- All these different representations are equal to `255` in JavaScript.

Loading…
Cancel
Save