JavaScript types and variables
JavaScript is not a typed language, since types are not declared and variables can receive different types, but data values do have types. The main types are Number, String, Boolean, Array, Object, and Function. The first three are scalar types, and the last three are also objects. A value is treated differently in the same expression if it has one type or another. For example, in an expression such as a = b + c, the value of a will be different if b and c are numbers (they will be added) or if one of them is a string (they will be concatenated).
Values can be compared, and their types are important if the comparison is strict (for example, using === instead of ==). But it can be confusing to rely on such conversions ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access