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
🌐
freeCodeCamp
freecodecamp.org › news › var-let-and-const-whats-the-difference
Var, Let, and Const – What's the Difference?
April 2, 2020 - Unlike var which is initialized as undefined, the let keyword is not initialized. So if you try to use a let variable before declaration, you'll get a Reference Error. Variables declared with the const maintain constant values.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › difference-between-var-let-and-const-keywords-in-javascript
Difference between var, let and const keywords in JavaScript - GeeksforGeeks
When using let in a loop, each iteration of the loop creates a new instance of the variable. This is different from var, which shares the same variable across all iterations. ... Trying to access i outside the loop causes an error since it’s ...
Published   January 16, 2026
Discussions

When should you use "var", "let", or "const" in JavaScript code - Stack Overflow
New to JavaScript and a beginner. I came across JavaScript variables and realized there are three different ways to go about them (var, let and const). Do they each have a specific purpose or you can More on stackoverflow.com
🌐 stackoverflow.com
Understanding var/let and const
“let” and “const” are relatively new to JS, and are what you should use now. If the materials you’re learning from use “var” and don’t explain very soon why not to, find some newer materials. “var” works in subtly different ways that can be confusing and prone to errors, mainly dealing with variable scope. See this post for some more in-the-weeds explanation of var vs let. More on reddit.com
🌐 r/Frontend
20
9
April 10, 2022
Difference between var, let and const
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. More on reddit.com
🌐 r/learnjavascript
31
57
March 28, 2022
let vs const vs var
It's leftover from before ES6. There's a lot of good programming, libraries, and tutorials created before ES6 that use var, and nobody is going to bother changing them now... but today, there's virtually no reason to use it. Using var might introduce a weird bug into your code that let/const wouldn't. Existing code that uses var works around that. Now with let/const, we don't need to worry about it. Use const by default. If you really need to change a variable's value, use let. Never use var. More on reddit.com
🌐 r/learnprogramming
8
0
February 19, 2022
🌐
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.
🌐
W3Schools
w3schools.com › js › js_let.asp
JavaScript Let
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:
🌐
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 - It's ideal for constants, objects, or arrays where you don't want to change the reference, but you may need to modify the object itself. In modern JavaScript/TypeScript, avoid using var unless absolutely necessary. Prefer let and const to ensure better scoping and reduce potential bugs.
🌐
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 - 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.
Find elsewhere
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Statements › let
let - JavaScript | MDN
Note that let is allowed as an identifier name when declared with var or function in non-strict mode, but you should avoid using let as an identifier name to prevent unexpected syntax ambiguities. Many style guides (including MDN's) recommend using const over let whenever a variable is not ...
🌐
Medium
medium.com › @adarsh-d › differences-between-let-const-and-var-in-javascript-5ab152904784
Let vs Const vs Var in JavaScript: Understanding the Differences | by Adarsh Dayanand | Medium
March 17, 2023 - var is the original way to declare a variable in JavaScript. It is function-scoped, meaning that the variable can be accessed within the function where it is declared. It can also be reassigned and has hoisting, which means that the variable ...
🌐
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 - 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 › @ubaniiyke29 › difference-between-var-const-and-let-in-javascript-2cd4e65a0aa8
Difference Between Var, Const, and Let in Javascript | by Joseph Ubani | Medium
August 18, 2022 - The let variable can be redefined ... with the same name in different blocks. Const: The Const keyword has all the properties of let keyword, except the user cannot update it....
🌐
Will Vincent
wsvincent.com › javascript-var-let-const
JavaScript: var, let, and const | Will Vincent
September 14, 2017 - Until JavaScript ES6 arrived in 2015 there was only one way to declare variables: with the var keyword. Now there are two more options: let and const.
🌐
freeCodeCamp
freecodecamp.org › news › differences-between-var-let-const-javascript
var, let, and const in JavaScript – the Differences Between These Keywords Explained
January 11, 2023 - If you're just starting out using JavaScript, a few things you may hear about these keywords are: var and let create variables that can be reassigned another value. const creates "constant" variables that cannot be reassigned another value.
🌐
Medium
medium.com › @mandeepkaur1 › javascript-variables-var-let-and-const-understanding-the-difference-290177dd3d3c
JavaScript Variables: Var, Let And Const — Understanding the Difference | by Mandeep Kaur | Medium
September 12, 2018 - Constants are block-scoped, much like variables defined using the let statement. The value of a constant cannot change through re-assignment, and it can’t be re-declared. What will happen if we try to reassign the const variable?
🌐
Medium
medium.com › @viveksingh23 › all-about-var-let-const-in-javascript-75e1c3da05cd
let vs var vs const difference in JavaScript. | by Vivek Singh | Medium
July 28, 2025 - With const we have to declare a variable and initialize it with value in the same line. ... Initialization means assigning the value in the declared variable .Think it as putting an apple in that bucket that we bought just few minutes ago. ... Declaring the variable in one line and initialize it later. var a; a = 10; // allowed let b; b = 20; // allowed const c; c = 30; // not allowed SyntaxError: Missing initializer in const declaration
🌐
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 › @pravi7031 › javascript-var-let-and-const-a-comprehensive-guide-f4b2d052db13
JavaScript var, let, and const: A comprehensive guide | by Ravi Panchal | Medium
September 12, 2023 - Let variables can be reassigned, but only within the block of code in which they are declared. The const keyword was also introduced in ES6 and is used to declare constants.
🌐
ShiftAsia
shiftasia.com › community › var-let-const-hosting-and-temporal-dead-zone-in-javascript
Understanding Javascript variables declaration (var, let, const), Hosting mechanism and Temporal dead zone (TDZ)
December 6, 2025 - Uninitialized State: Unlike var (which is initialized to undefined during hoisting), let and const variables are not initialized when they are hoisted. They are put into an uninitialized state. The TDZ Period: The TDZ is the time period that begins when the scope is entered (e.g., when a { block is started) and ends when the variable's declaration line is executed and the variable is assigned a value (initialized). Exiting the TDZ: Once the JavaScript interpreter reaches and executes the line of code that declares and initializes the variable (e.g., let x = 10; or const PI = 3.14;), the variable exits the TDZ and becomes fully accessible.
🌐
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 - var is function-scoped and has been around since the early days of JavaScript. let is block-scoped and was introduced in ES6, offering a more predictable scoping mechanism. const is also block-scoped and is used to declare constants that cannot ...