number: numeric values such as 100 or 3.14159
string: Textual data, which can include numbers and symbols
boolean: true or false values
There are other primitive types (
function — but I will also save the discussion of these types for another time.
When data is encountered in a program, that data is said to be literal data. For example, if I write:
100 is called a number literal. If I write:
“Hello, world!” is a string literal. Literals are found throughout a program and I needed to describe what literal data is to distinguish it from a variable, which is just a name for a storage location in memory that can hold data.
You can see what the type of a literal is by calling a special function:
typeof. This function returns the type of data passed into it. Here are some examples of calling the
typeof function on some literal data:
typeof(100); // returns "number" typeof("hello"); // returns "string" typeof(false); // returns "boolean"
typeof function useful for avoiding all types of logic errors in your programs.