Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →In JavaScript, a variable declaration creates a named binding for a value, while a function packages instructions that you can call and, when needed, use to return a result. For new code, use const when you will not reassign the binding and let when you will; learn var mainly so you can recognize its different scope behavior. Start with named function declarations, then learn function expressions and arrow functions.
What does a JavaScript variable do?
A variable gives a name to a value so your code can use it later. More precisely, a declaration creates a binding between an identifier and a value. Here, learnerName is bound to the string "Mina":
const learnerName = "Mina";
The declaration keyword matters: const, let, and var differ in whether the binding can be reassigned and in the scope rules that apply. MDN introduces these declaration forms in its JavaScript language overview and explains them in Grammar and types.
When should you use const, let, or var?
Choose based on whether you need to assign a different value to the same binding. In modern beginner examples, prefer const by default and change to let when reassignment is part of the logic. var is an older form with different scope behavior, and is usually not the best choice for new examples.
#1 Best Overall
| Declaration | Can the binding be reassigned? | Scope behavior |
|---|---|---|
const |
No. Assign its initial value when declaring it. | Block-scoped. |
let |
Yes. | Block-scoped. |
var |
Yes. | Not block-scoped; it does not follow the usual lexical scope rules. |
Use let for a value you reassign
This counter starts at zero and then changes. Because the binding is reassigned, declare it with let:
let practiceCount = 0;
practiceCount = practiceCount + 1;
After the second line, practiceCount is 1.
Use const when the binding stays assigned to the same value
A const binding must be initialized when declared and cannot later be assigned a different value:
const learnerName = "Mina";
// learnerName = "Jo"; // TypeError: the binding cannot be reassigned
This restriction applies to the binding, not automatically to everything it refers to. An object declared with const can still have a property changed, because that operation does not reassign the binding:
const learner = { name: "Mina" };
learner.name = "Jo"; // The object changes; learner still refers to that object
If you need an object or array itself to be immutable, const alone does not provide that guarantee.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Why var behaves differently
let and const are block-scoped: their bindings are limited to the surrounding block, typically the code between a pair of curly braces. var is not block-scoped, so a declaration inside a block can be visible outside that block within its function scope or the surrounding script. That difference can cause surprises when code grows. MDN documents declaration and scope details in Grammar and types and Statements and declarations.
What is a JavaScript function?
A function is a reusable piece of code. You can call it by name, pass values called arguments, and use a return statement to send a result back to the caller. A function declaration begins with the function keyword:
function greet(name) {
return `Hello, ${name}!`;
}
const message = greet("Mina");
In this example, name is the parameter in the function definition. The string "Mina" is the argument passed when calling greet. The function returns "Hello, Mina!", which is assigned to message.
A function can also perform an action without returning a useful value. If a function reaches its end without a return statement that supplies a value, its call evaluates to undefined. MDN covers declarations, calls, parameters, and return values in its Functions guide.
How do function expressions and arrow functions differ?
Functions can be values, too. That means you can assign one to a variable binding. First, here is a function expression assigned to a const:
Rank #4
const double = function (number) {
return number * 2;
};
const result = double(4); // 8
The function is created as part of an expression and assigned to double. The binding is available only after the declaration has run; calling it before that point is not equivalent to calling a function declaration earlier in its scope.
An arrow function is another function expression form. It can make small functions more compact:
const double = (number) => number * 2;
const result = double(4); // 8
When an arrow function has a single parameter, parentheses around that parameter can be omitted. For a body with multiple statements, use braces and an explicit return if it should produce a value:
Recommended Free Tools
Best Value
const double = (number) => {
const doubled = number * 2;
return doubled;
};
Arrow functions are not interchangeable with ordinary functions
Arrow functions do not have their own this, arguments, super, or new.target. In particular, their this value comes from the surrounding context rather than being set by how the arrow function is called. That makes arrows useful in some callbacks, but not a universal shorter replacement for a function declaration or function expression. MDN explains arrow function behavior in its Functions guide.
| Form | How it is written | Key distinction for a beginner |
|---|---|---|
| Function declaration | function greet(name) { ... } |
Named declaration form; use it first to learn defining and calling functions. |
| Function expression | const greet = function (name) { ... }; |
A function value assigned to a binding; the binding must be initialized before it can be called. |
| Arrow function | const greet = (name) => ...; |
Compact expression syntax with lexical this and no own arguments, super, or new.target. |
How these pieces fit together
Bindings hold values, including function values. A function can read an argument, calculate a result, and return it; another binding can keep that result for later use. This short example combines a reassigned counter, a named function declaration, and a function call:
let practiceCount = 0;
function addPractice(count) {
return count + 1;
}
practiceCount = addPractice(practiceCount);
Once that pattern makes sense, try expressing a small function as a function expression and then as an arrow function. Keep the declaration keywords and function forms distinct: they solve related but different parts of writing JavaScript.
Quick Recap
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.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.




