The Number Data Type in JavaScript

By Chris Minnick, Eva Holland

One type of data that JavaScript understands is the number data type. Numbers can be positive or negative, as well as whole numbers or decimal numbers. Numbers are stored in variables without using quotation marks.

The range of possible numbers that can be used in JavaScript goes from very, very small to very, very large. The biggest number that you can use in JavaScript is far greater than the number of stars in the universe. It’s even bigger than the number of atoms in the universe! JavaScript can do any math problem or counting problem that you would want it to do.

One thing to watch out for, however, is what happens when you try to combine two different data types, such as strings and numbers.

JavaScript generally tries to be pretty clever. If you open the console and type “10” + 10, JavaScript will assume that you meant for both pieces of data to be strings, and will put them together and give you the result 1010.

On the other hand, if you type 10 * “10”, JavaScript will assume that you meant for the string “10” to actually be the number 10, and it will give you the result 100. JavaScript does this because it knows there is no way to multiply two strings together.