1.5 Data Types

JavaScript has different data types: numbers, booleans, strings, objects, and arrays, and more.

Here are some examples:

let length = 16; // type: number
let lastName = "Johnson"; // type: string
let obj = { firstName: "John", lastName: "Doe" }; // type: object

What exactly are data types?

In programming, data types are an important concept. It tells the computer what a piece of code is and how it should be treated.

Let's go over the different types:

Numbers

Every number you can think of fall under the number type.

Numbers can be written with or without decimals.

let numOne = 34.00; // written with decimals
let numTwo = 34; // written without decimals

Extra large or extra small numbers can be written with scientific notation.

let x = 123e5; // 12300000
let y = 123e-5; // 0.00123

Booleans

Booleans can only have two values: true or false.

let isRaining = false;
let isSunny = true;

Strings

A string (or a text string) is a series of characters like this sentence.

Strings are written with quotes. You can use single or double quotes.