bugl
bugl
HomeLearnPatternsSearch
HomeLearnPatternsSearch

Loading lesson path

Learn/JavaScript/JavaScript Foundations
JavaScript•JavaScript Foundations

JavaScript Data Types

Concept visual

JavaScript Data Types

Pointer walk
two pointers
leftright102132436485116
left=0
right=6
1
3

Start at both ends

A

JavaScript variable can hold

8 types of data. 7 Primitive

Data Types and

1 Object Data Type. The Object data type can hold many different object types.

Type

Description

Number

A number representing a numeric value

Bigint

A number representing a large integer

String

A text of characters enclosed in quotes

Boolean

A data type representing true or false

Undefined

A variable with no assigned value

Null

A value representing object absence

Symbol

A unique primitive identifier

Object

A collection of key-value pairs of data

Examples

// Number let length = 16;
let weight = 7.5;
// BigInt let x = 1234567890123456789012345n;
let y = BigInt(1234567890123456789012345)
// Strings let color = "Yellow";
let lastName = "Johnson";
// Boolean let x = true;
let y = false;
// Undefined let x;
let y;
// Null let x = null;
let y = null;
// Symbol const x = Symbol();
const y = Symbol();
// Object const person = {firstName:"John", lastName:"Doe"};
// Array Object const cars = ["Saab", "Volvo", "BMW"];
// Date Object const date = new Date("2022-03-25");

The Concept of Data Types

In programming, data types is an important concept. To be able to operate on variables, it is important to know something about the type. Without data types, a computer cannot safely solve this:

let x = 16 + "Volvo";
Does it make any sense to add "Volvo" to sixteen? Will it produce an error or will it produce a result?

JavaScript will treat the example above as:

let x = "16" + "Volvo";

When adding a number and a string, JavaScript will treat the number as a string.

Example

let x = 16 + "Volvo";

Previous

JavaScript Scope

Next

JavaScript Style Guide