In my opinion nowadays it is better to use let and const.

According to the ES6 standard, these options are more convenient with their scope. Both give us the so-called block scope. This means that the scope of their use can be limited to a block of code, such as a for loop or an if expression. This gives the developer more flexibility in choosing the scopes of variables.

In addition, if we consider these options, then you will not be able to change the variable declared with const, unlike var and let.

Generally speaking, let and const are often used now, depending on the need.

Answer from nixanosize on Stack Overflow
๐ŸŒ
Reddit
reddit.com โ€บ r/learnjavascript โ€บ difference between var, let and const
r/learnjavascript on Reddit: Difference between var, let and const
March 28, 2022 -

Hi everyone!

I'm pretty new to web development and have started to read a little bit about javascript. Right now I'm trying to learn how to declare a function but realized that there is different ways to do this using var, let or const. Since I'm new to this, most of the explanation on the internet is pretty advanced to understand atm, so could anyone explain the differences for me very short short and easy, alternatively give me a link that explain it in pretty easy terms?

Thanks in advance!

(Edit: Thank you so much for the answers, rly appreciate it!)

Top answer
1 of 5
52
Using the function keyword creates a function declaration. Function declarations are hoisted to the top of the scope, thus the following code works fine: add(1, 2) function add (a, b) { return a + b } There are readability advantages to using the function keyword as it clearly communicates that this is a function. We can also create an anonymous function expression and, because functions in JavaScript are first class citizens, assign a function to a named variable with let, const or var. Keep in mind though, variables declared with let and const are hoisted, but not initialized with a value. Whereas variables declared with var are hoisted and initialized with the value undefined. So because add is invoked prior to it's initialization in the code below we encounter an error. With let/const: add(1, 2) // Reference error - cannot access 'add' before initialization const add = function (a, b) { return a + b } With var: add(1, 2) // Type error - 'add' is not a function (as it is initialized as undefined when hoisted) var add = function (a, b) { return a + b } If you're assigning a function to a variable I can't think of any situation where you wouldn't use const. Functions should always be pure and immutable whenever possible. Given a certain input, the output should always be consistently the same. Using const protects you from accidentally reassigning a variable containing a function expression. Compare this to use of the function keyword, which allows you to declare a named function twice, overiding the previous: function add (a, b) { return a + b } function add (a, b) { return a - b } add(2, 1) // 1 This is a disadvantage of function declarations versus expressions. Provided you understand the pros/cons and how hoisting works, it is really personal choice whether you prefer function declarations versus expressions.
2 of 5
22
All you need to remember is that var should never be used in modern JavaScript. Functions should either use the function keyword or const (with arrow functions). Objects/arrays should always be const. Just always use const until you canโ€™t.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ difference-between-var-let-and-const-keywords-in-javascript
Difference between var, let and const keywords in JavaScript - GeeksforGeeks
This happens because let variables are hoisted but not initialized, so they remain in the TDZ until the declaration is executed. ... Hoisting with const: The variable x is declared with const, which is block-scoped and not hoisted.
Published ย  January 16, 2026
๐ŸŒ
Medium
medium.com โ€บ @robinviktorsson โ€บ understanding-the-differences-between-var-let-and-const-in-javascript-and-typescript-0ddd90c0b672
Understanding the Differences Between var, let, and const in JavaScript and TypeScript ๐Ÿ’ป | by Robin Viktorsson | Medium
March 10, 2025 - This means that the variable declaration itself is moved to the top of the function or global context, but its assignment remains in place. Unlike let and const, var is initialized with undefined when hoisted.
๐ŸŒ
DEV Community
dev.to โ€บ jmitchell38488 โ€บ const-let-var-javascript-variables-and-immutability-13ci
const, let, var; JavaScript variables and immutability - DEV Community
September 24, 2020 - The three keywords together provide the same fundamental functionality, but differ in the way that they provide it. var and let are reassignable values, while const has limited mutability.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ var-let-and-const-whats-the-difference
Var, Let, and Const โ€“ What's the Difference?
April 2, 2020 - Just like let, const declarations are hoisted to the top but are not initialized. So just in case you missed the differences, here they are: var declarations are globally scoped or function scoped while let and const are block scoped.
Find elsewhere
๐ŸŒ
DEV Community
dev.to โ€บ jps27cse โ€บ difference-between-var-let-and-const-in-javascript-53c
Difference between var, let and const in JavaScript - DEV Community
September 20, 2023 - Using the flexible and popular programming language JavaScript, programmers may create dynamic and interactive online apps. The ability to store and change data via variables is one of the fundamental ideas in JavaScript. Var, let, and const are the three main ways to declare variables in JavaScript.
๐ŸŒ
Appsmith
community.appsmith.com โ€บ content โ€บ guide โ€บ variables-javascript-comprehensive-guide-var-let-and-const
Variables in Javascript: A Comprehensive Guide to Var, Let, and Const | Appsmith Community Portal
August 11, 2023 - If you declare a variable with var inside a block, it's actually available to the entire surrounding function or global scope. Because of these peculiarities, and with the introduction of let and const in ES6 (ECMAScript 2015), the use of var has become less common in modern JavaScript, and it's often recommended to use let or const instead for clearer scoping rules and better maintainability.
๐ŸŒ
Medium
medium.com โ€บ @larry.sassainsworth โ€บ let-vs-var-vs-const-in-javascript-8b898f868394
Let vs Var vs Const in Javascript | by Larry Sass-Ainsworth | Medium
December 15, 2019 - Var declarations were the only type of variables before ES6, and Let and Const were introduced to fix some of its issues. The main differences with Var are its scope, its ability to be re-declared and updated, and the fact that it is hoisted.
๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ js_let.asp
W3Schools.com
ES6 introduced the two new JavaScript keywords: let and const. These two keywords provided Block Scope in JavaScript: Variables declared inside a { } block cannot be accessed from outside the block:
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Statements โ€บ const
const - JavaScript | MDN
The const declaration creates an immutable reference to a value. It does not mean the value it holds is immutable โ€” just that the variable identifier cannot be reassigned. For instance, in the case where the content is an object, this means the object's contents (e.g., its properties) can ...
๐ŸŒ
CodeParrot
codeparrot.ai โ€บ blogs โ€บ javascript-var-vs-let-vs-const
JavaScript Var vs Let vs Const: Key Differences & Best Uses
September 1, 2024 - It is function-scoped, meaning a var variable is only accessible within the function where it is declared. If declared outside a function, it becomes global. Unlike let and const, which are block-scoped, var does not respect block boundaries (e.g., ...
๐ŸŒ
Quora
quora.com โ€บ When-should-I-use-const-and-let-instead-of-var-in-Javascript
When should I use const and let instead of var in Javascript? - Quora
Answer (1 of 10): var Don't use it. The only thing var gives you is weird unexpected behaviors. For example [code]for (var i = 0; i
๐ŸŒ
Medium
medium.com โ€บ @jackpritomsoren โ€บ difference-between-var-let-and-const-in-javascript-c6236899ca4d
Difference between var, let and const in JavaScript | by Jack Pritom Soren | Medium
September 20, 2023 - Use let and const instead of var when writing JavaScript code to prevent unexpected scope problems and create more predictable, maintainable code. If you need to reassign a variable, use let; if you wish to declare constants, use const.