JS JavaScript

JavaScript: Variables & Data Types

What you will learn

How to declare variables and understand the main data types. JavaScript is dynamically typed: a variable can hold a string now and a number later.

let and const (modern)

let name = "Alice";        // can reassign later
const birthYear = 1998;    // cannot reassign
let age = 25;

let is block-scoped (visible only inside { }). const makes the binding immutable — but objects/arrays declared with const can still have their content modified:

const fruits = ["apple"];
fruits.push("banana");  // allowed
// fruits = ["cherry"]; // TypeError: assignment to constant

Avoid var

var is function-scoped and hoisted with confusing behavior. Prefer let and const in modern code.

Data types

Type Example Notes
number 42, 3.14 Both integers and floats share this type
string "hello", 'world' Can use single or double quotes
boolean true, false
object {key: "value"} Includes arrays and null
undefined let x; A declared variable with no assigned value

Quick check below!