computer-scienceangular-roadmapbackend-roadmapblockchain-roadmapdba-roadmapdeveloper-roadmapdevops-roadmapfrontend-roadmapgo-roadmaphactoberfestjava-roadmapjavascript-roadmapnodejs-roadmappython-roadmapqa-roadmapreact-roadmaproadmapstudy-planvue-roadmapweb3-roadmap
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
977 B
977 B
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
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
and255.0
are equivalent, as JavaScript treats both as the same number.0xff
represents255
in hexadecimal notation.0b11111111
represents255
in binary notation.0.255e3
is255
in exponential notation.- All these different representations are equal to
255
in JavaScript.