JavaScript Data Structures
Learn about JavaScript's data types and data structures.

1. Dynamic Typing

JavaScript is a dynamically typed language. This means you don't have to specify the data type of a variable when you declare it.

JavaScript Code
Live JavaScript representation with highlighted changes
let foo = 42; // foo is now a number
foo = "bar"; // foo is now a string
foo = true; // foo is now a boolean
console.log(typeof foo);

2. Type Coercion

JavaScript is also weakly typed, which means it allows implicit type conversion when an operation involves mismatched types.

JavaScript Code
Live JavaScript representation with highlighted changes
const foo = 42; // foo is a number
const result = foo + "1"; // JavaScript coerces foo to a string
console.log(result);

3. Primitive Types

JavaScript has seven primitive data types. Let's check their types with the typeof operator.

JavaScript Code
Live JavaScript representation with highlighted changes
console.log(typeof 42); // number
console.log(typeof "hello"); // string
console.log(typeof true); // boolean
console.log(typeof 123n); // bigint
console.log(typeof Symbol('id')); // symbol
console.log(typeof undefined); // undefined
console.log(typeof null); // object (this is a famous quirk!)
Console Output