Integers in JavaScript

By: Dusty Arlia
Published on Tuesday, May 14, 2013, 10:37 AM
Last Updated on Saturday, July 11, 2015 at 5:09 PM
Total Updates: 2

Integers are numbers that can be written without a fractional or decimal component. They include negative numbers (-1, -2, -3, etc.), zero (0), and whole numbers (1, 2, 3, etc.). In JavaScript, all numbers fall under the number data type. You can have numbers in strings, but they will not be handled like numbers.

Here is an example of how the JavaScript interpreter interprets numbers:

//remember to not use quotes
//when initializing your numbers
//quotes are for string values
var x = 5;
var y = 5.0;
if (x === y) {
    document.write("x and y have the same value");
}

This example prints x and y have the same value to the screen.

Here is another example:

var x = 5;
var y = 5.1;
if (x === y) {
    document.write("x and y have the same value");
}
else {
    document.write("x and y do NOT have the same value");
}

In this example, x and y do NOT have the same value gets printed to the screen.

Comments:

Ad: