Introduction to DataTypes and Values
We'll start with an article that describes how a computer stores values and some primitive types such as numbers and strings. You can think of the "type of a value" as defining how it is stored, named, and manipulated. For example, a calculator program uses the type "number", which holds "numeric values" and supports "arithmetic operations". JavaScript has two types: "primitive" and "object". Examples of primitive types include numbers, strings, and Booleans. Object types include arrays, objects, and functions.
Here are some things to remember when using JavaScript data types:
- Primitive types are "immutable"; their "values" cannot be changed once created;
- Object types are "mutable"; their values can change once created; and
- Although JavaScript supports types, it is a "dynamically typed" language, which means that you do not have to define the type of variable in a JavaScript program (but this is not a best practice).
Special numbers
There are three special values in JavaScript that are considered numbers but don't behave like normal numbers.
The first two are Infinity
and -Infinity
, which represent the positive and negative infinities. Infinity - 1
is still Infinity
, and so on. Don't put too much trust in infinity-based computation, though.
It isn't mathematically sound, and it will quickly lead to the next special number: NaN
.
NaN
stands for "not a number", even though it is a value of the number type. You'll get this result when you, for example, try to calculate 0 / 0
(zero divided by zero), Infinity - Infinity
, or any number
of other numeric operations that don't yield a meaningful result.