Data Types

Go back to JavaScript Index

Data types used in JS

There are 7 fundamental data types in JavaScript, being:

  • Number
  • String
  • Boolean
  • Null
  • Undefined
  • Object
  • Symbol

For now, we will only focus on the first 5.


In the examples on the previous page, you saw that we can add the values of x and y together and get the result. The result was a number just like the two initial values (x and y)..

let x = 2019;
let y = 1;
let z = x + y;
1.0 | Data type: number

The typeof() operator returns the data type - in this case of the variable z


A string consist of a single character or a combination of characters:

let greeting = "Hello World";
1.1 | Datatype: string

When assigning strings as values, always write them in quotation marks.

If we write a number inside quotation marks, the data type will be string. Strings don't "add up" the same way that numbers do. 1 + 1 = 2 when the data type is number, but "1" + "1" = "11" when the data type is string.


Log the code from the example 1.0 in the console again, but this time type in the values in quotation marks, changing the data type to string. Add the two values, just like in the example.

Use the typeof() operator to find out what the data type of z is.


The Boolean data type has two possible values: true or false

let isMonday = true;
1.2 | Data type: boolean

This data type is often used in connection with conditional statements.

Next up

What's next?

Next up: The JS Document