Variables & Data Types
Variables store data in your program. Learn let, const, var, and the basic data types: string, number, boolean. This is a foundational concept in programming and web interactivity that professional developers rely on daily. The explanations below are written to be beginner-friendly while covering the depth and nuance that comes from real-world JavaScript experience. Take your time with each section and practice the examples
25 min•By Priygop Team•Last updated: Feb 2026
Variables in JavaScript
A variable is a named container that stores a value. In modern JavaScript, use let for values that change, and const for values that never change. Avoid var (old style). JavaScript is dynamically typed — you don't need to declare the type, it figures it out automatically.
JavaScript Data Types
- String — Text in quotes: 'Hello' or "World"
- Number — Any number: 42, 3.14, -100
- Boolean — true or false
- null — Intentionally empty value
- undefined — Variable declared but not assigned
- Array — List of values: [1, 2, 3]
- Object — Key-value pairs: { name: 'Alice', age: 25 }
Variables Example
Example
// let — can be changed later
let name = "Alice";
let age = 25;
let isStudent = true;
// const — cannot be changed
const PI = 3.14159;
const country = "India";
// Printing variables
console.log("Name:", name);
console.log("Age:", age);
console.log("Student:", isStudent);
console.log("PI:", PI);
// Changing a let variable
age = 26;
console.log("Next year:", age);
// typeof — check the type
console.log(typeof name); // string
console.log(typeof age); // number
console.log(typeof isStudent); // booleanTry It Yourself: Variables
Try It Yourself: VariablesJavaScript
JavaScript Editor
✓ ValidTab = 2 spaces
JavaScript|15 lines|424 chars|✓ Valid syntax
UTF-8