Previous Next

JavaScript Data Types

JavaScript offers different data types that you can employ to save different kinds of data.

There are mainly two types of data types in JavaScript:

Primitive Data Types

There are six primitive data types in JavaScript:

String

String is employed to depict text data, in single (' ') or double (") quotes.

Example:

// Double quotes
let name = "James";
// Single quotes
let name = 'John';

Number

Numbers are used to denote integer and floating-point numbers.

Example:

let number1 = 24;
let number2 = 4.33;

Boolean

Boolean data types are used to denote logical values that can be true or false.

Example:

let isTrue = true;
let isFalse = false;

Undefined

The undefined data type is used to denote a value that is not assigned.

Example:

let num;
console.log(num); // undefined

Symbol

The Symbol data type is used to denote an extremely unique identifier.

Example:

let val1 = Symbol("Hello");
let val2 = Symbol("Hello");

Non-primitive data types

There are mainly three types of non-primitive data types in JavaScript:

Object

JavaScript objects are enclosed within curly braces {}.

Example:

let student = {
   name: "John",
   age: 22,
   education: "3rd year"
};

Array

Arrays are enclosed in square brackets. Array elements are divided by commas.

Example:

let numbers = [20, 40, 60, 80]
console.log(numbers[0]);
Previous Next