Variables are used to store data. In JavaScript, you declare variables using var, let, or const.
let name = "John"; // Variable that can be reassigned
const age = 30; // Constant variable that cannot be reassigned
var isStudent = true; // Older way to declare variables, function-scoped
This is a key difference between var and let/const.
let and const, on the other hand, are block-scoped — limited to {} blocks (like inside an if-statement or loop).function example() {
if (true) {
var x = 10;
let y = 20;
}
console.log(x); // ✅ works (function-scoped)
console.log(y); // ❌ error (block-scoped)
}
JavaScript has different data types, including numbers, strings, booleans, and arrays.
let number = 42; // Number
let string = "Hello World"; // String
let isActive = false; // Boolean
let numbers = [1, 2, 3]; // Array
Operators are used to perform operations on values and variables.
let sum = 10 + 5; // Arithmetic operator
let isEqual = (10 === "10"); // Comparison operator
let isTrue = (true && false); // Logical operator