New: Complete Beginner's Guide to Coding is now available in Premium
Updated: Indian Govt Exam roadmaps now include salary breakdowns & timelines
Tip: Use the Career Hub to explore all career paths in one place
Tutorials JavaScript JavaScript Variables

JavaScript Variables

JavaScript

Variables store data. JavaScript has 3 ways to declare variables:

  • let — can be changed later (use this most!)
  • const — cannot be changed (use for constants)
  • var — old way, avoid in modern code

Data Types

JavaScript automatically detects the type: string, number, boolean, array, object.

Example — JAVASCRIPT
// String
let name = "Priya";

// Number
let age = 20;

// Boolean
const isStudent = true;

// Array
let skills = ["HTML", "CSS", "JS"];

// Object
let person = {
    name: "Rahul",
    age: 22,
    city: "Mumbai"
};

console.log(name);        // Priya
console.log(skills[0]);   // HTML
console.log(person.city); // Mumbai
Result
▶ "Priya"
▶ "HTML"
▶ "Mumbai"