In JavaScript, a variable declaration creates a named binding, while a data type describes the value that binding currently holds. Use const when you do not need to reassign a binding, let when you do, and learn var mainly to understand older code and its different scope behavior.
What is a JavaScript variable?
A variable is a named binding that lets code refer to a value. In let score = 10;, score is the binding and 10 is its current value. The declaration keyword controls how the binding behaves; it does not permanently assign a type to the variable name.
As an Amazon Associate I earn from qualifying purchases.
JavaScript is dynamically typed: a binding can refer to values of different types at different times. The MDN JavaScript language overview explains this behavior.
let value = 42;
console.log(typeof value); // "number"
value = "hello";
console.log(typeof value); // "string"
typeof inspects the current value. Here, it returns "number" first and "string" after reassignment.
#1 Best Overall
Should you use let, const, or var?
For ordinary modern JavaScript, prefer const unless the binding needs reassignment; use let for bindings that will be reassigned. Understand var because it appears in existing code, but its scope behavior can be surprising. The MDN language overview discourages using var in modern code.
| Declaration | Scope | Reassignment | Initialization | Before initialization |
|---|---|---|---|---|
let |
Block scope | Allowed | May be omitted; an unassigned binding evaluates to undefined |
Cannot be accessed before its initialization point |
const |
Block scope | Not allowed | Required | Cannot be accessed before its initialization point |
var |
Associated with the surrounding variable environment; a block alone does not limit it | Allowed | May be omitted | Different behavior from lexical declarations; its scope is not limited to a block |
The ECMAScript 2026 specification says that “let and const declarations define variables that are scoped to the running execution context’s LexicalEnvironment.” See the ECMAScript 2026 declarations specification. In everyday terms, a block is a section of code enclosed in braces, and a block-scoped binding is visible only within that section.
Rank #2
Reassignment and mutation are different
Reassignment makes a binding refer to a different value. Mutation changes the contents of an object or array while the binding still refers to that same value. const prevents reassignment, not mutation.
let score = 10;
score = 11; // reassignment is allowed
const settings = { theme: "light" };
settings.theme = "dark"; // mutation is allowed
// settings = {}; // TypeError: reassignment is not allowed
The MDN const reference covers initialization, reassignment, and mutation of objects and arrays.
Block scope and the temporal dead zone
let and const bindings are not accessible before their declaration is initialized. That interval is called the temporal dead zone. By contrast, var is tied to the surrounding variable environment, so declaring it inside a block does not confine it to that block.
if (true) {
let blockValue = "inside";
var functionValue = "visible outside this block";
}
// blockValue is not available here
console.log(functionValue); // "visible outside this block"
What data types does JavaScript have?
ECMAScript defines seven primitive value types and the Object type. These categories describe values, not declaration keywords. The language categories are specified in ECMAScript 2024.
Rank #4
undefined: often the value of a declared binding that has not been assigned another value.null: an intentional absence of an object value.boolean: eithertrueorfalse.number: ordinary numeric values.bigint: integer values for use cases beyond ordinaryNumbervalues.string: text.symbol: a unique symbol value.object: structured values, including ordinary objects and arrays.
Arrays and functions are objects in JavaScript’s language model, even though they are often treated as separate practical categories when learning or building programs.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchPC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11How do you check a value’s type with typeof?
Use typeof to get a string describing the type category of a value in common cases. It reports the value at the time the expression runs, so call it again after reassignment if you want to inspect the new value.
Best Value
const count = 500;
const label = "500";
console.log(typeof count); // "number"
console.log(typeof label); // "string"
The quotation marks make "500" text; it is not a number just because its characters are digits. MDN uses this distinction in its beginner material on variables and data types.
Quick Recap
How should you choose a declaration?
- Start with
constwhen you do not intend to make the binding refer to another value. - Choose
letwhen later code must assign a different value to that binding. - When reading
var, remember that a surrounding block does not limit its visibility in the way it does forletandconst. - Use
typeofto inspect a value when needed, and remember that the type belongs to the value currently held, not permanently to the variable name.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




