Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →JavaScript variables are bindings to values, functions are values that can also be called, and objects group properties that may be shared through references. For everyday code, use const when a name will not be reassigned and let when it will; understand var mainly because it appears in older code.
How JavaScript variables and bindings work
A variable is a named binding that lets code refer to a value. JavaScript is dynamically typed: a binding declared with let can refer to values of different types over time.
As an Amazon Associate I earn from qualifying purchases.
let value = 3;
value = "three"; // allowed: the binding now refers to a string
Choose a declaration according to whether the binding needs to point to a different value later. MDN’s practical guidance is: “Use const when you can, and use let when you have to.”
Free tools Windows power users keep installed
One-click scans. No signup required.
const for bindings you will not reassign
A const declaration must have an initializer, and its binding cannot be assigned a different value later. This does not make the value itself immutable. If the value is an object, its properties can still change.
#1 Best Overall
const user = { name: "Ari" };
user.name = "Sam"; // allowed: the binding still refers to the same object
let for bindings that need a new value
A let binding can be reassigned. If declared without an initializer, it starts with the value undefined.
let count = 0;
count += 1; // allowed: count is reassigned
var in older code
var is legacy declaration syntax that readers will encounter. Unlike let and const, it is scoped to a function or, outside a function, the global scope—not to an ordinary block. As a result, a var declared inside an if block can still be available after that block, within its enclosing function or global scope. MDN uses let and const in its examples. See MDN’s guide to grammar and types and its JavaScript language overview.
Rank #2
How scope affects access to variables
Scope determines where a binding can be accessed. let and const are block-scoped: a binding declared inside braces belongs to that block. var is function-scoped or global-scoped, so ordinary braces do not limit its availability.
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 & 11if (true) {
let insideBlock = "here";
var outsideBlock = "still available";
}
// insideBlock is not available here
console.log(outsideBlock); // "still available"
Declarations and the temporal dead zone
A let or const binding cannot be accessed until execution reaches its declaration. Trying to read it earlier in the same scope throws a ReferenceError; this interval is called the temporal dead zone.
console.log(name); // ReferenceError
let name = "Ari";
An outer binding with the same name does not make that early access fall back to the outer value: the inner binding is already the relevant name in its scope, but it is not initialized yet. For the declaration and scope rules, see MDN’s grammar and types guide.
What functions do—and why they are values
A function is callable code that can take inputs and return a result. Functions are also values: they can be stored in variables, passed to other functions as arguments, and returned from other functions.
Rank #4
function greet(name) {
return `Hello, ${name}`;
}
const sayHello = greet;
console.log(sayHello("Ari")); // "Hello, Ari"
Here, sayHello refers to the same function as greet; assigning it does not call the function. Parentheses with an argument, as in sayHello("Ari"), call it. For a beginner-focused explanation, see MDN’s functions module.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitchesNested functions and closures
A function declared inside another function can access bindings from its enclosing scope. A function together with the surrounding bindings it can access is called a closure. This lets related helper behavior stay near the code that uses it.
Best Value
function makeGreeter(greeting) {
return function (name) {
return `${greeting}, ${name}`;
};
}
const greet = makeGreeter("Welcome");
console.log(greet("Ari")); // "Welcome, Ari"
The returned inner function can still read greeting from the call to makeGreeter. Scope works outward in this example: the inner function can use an enclosing binding, but the enclosing function cannot access a variable declared only inside the inner function. See MDN’s closures guide.
How objects, properties, and references work
An object groups related properties. Read a property with dot notation when its name is a simple identifier, or bracket notation when the name is held in a variable or needs to be expressed as a string.
const user = { name: "Ari", score: 1 };
console.log(user.name); // "Ari"
console.log(user["name"]); // "Ari"
const property = "score";
console.log(user[property]); // 1
Assignment shares an object reference
When one variable is assigned an object held by another, the assignment copies the reference, not the object. Both bindings then refer to the same object, so a change made through either is visible through the other.
const first = { score: 1 };
const second = first;
second.score = 2;
console.log(first.score); // 2
Two separately created object literals are distinct objects, even if they contain identical properties. Also, const prevents rebinding a name; it does not freeze the object reachable through that name. These reference and property basics are covered in MDN’s JavaScript language overview.
Quick Recap
A practical rule for writing and reading JavaScript
- Use
constwhen you will not reassign the binding, including when it refers to an object whose properties may change. - Use
letwhen the binding needs to be reassigned. - Recognize
varas function-scoped or global-scoped syntax in older code; braces alone do not contain it. - Remember that functions can be passed around as values and that nested functions can retain access to enclosing bindings.
- When an object is assigned to another binding, expect both names to refer to the same object unless you explicitly create a copy.
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.




