Integer Numbers

Data Types

Integer Numbers

🙋 Need help? Ask an expert now!

Integer numbers in JavaScript represent whole numbers. They have range of values depending on the size of the memory used. For most cases, integer values can hold numbers from -9007199254740992 to 9007199254740992. As mentioned previously, their underlying type is a floating-point number (IEEE-754 standard). Take a look at the sample code below to learn how integers and declared and used.

The sample code above contains 6 variables. The first three should look familiar as they are just variables that are declared and assigned a value. The fourth and fifth variable, a and b are declared on the same line. Calling more than one variable in one line is common in JavaScript. This can be achieved using a comma to separate each variable.

The two variables sum and div are not assigned a specific integer, but an addition/division of two variables. This is also common as the expressions on the right are evaluated before assigning the variable an integer. Notice that div is actually equal to "Infinity". Dividing any number by 0 will give you this result. The only exception is "0 / 0", which will return NaN (abbreviation for Not a Number).

Edit Me on GitHub!

Application Question

What does the following code segment print on the console?

let varOne = 5/0;
console.log(varOne);