Basic Data Types and Values
8.28 is a
"Hello" is a
values, one of the fundamental things that a program manipulates.
The number type includes integer and floating point numbers.
A string may have one more more characters, it must be quoted by matching single quotes or double quotes.
The boolean is a logical type has only two values:
All above types are called “primitive”, because their values can contain only a single thing (be it a string or a number or whatever).
undefined is another primitive value. If a variable has the value
undefined, it means the variable has been assigned a value yet.
symbol type is not widely used in software so we will ignore it for now.
In contrast, the
object type is for more complex data structures.
typeof operator returns the type of the argument(the input value), it's convenient to make a quick check.
It supports two forms of syntax:
As an operator:
console.log(typeof 25); // number console.log(typeof('Hello'); // string
Mixing Numbers and Strings
When you want to mix text and numbers in an expression, such as you like to show a message: "My age is 12." You can simply join the string text and the number using the
console.log("My age is " + 808); // My age is 808