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
🌐
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
🌐
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:
Discussions

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
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
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
58
March 28, 2022
When should I use var vs let vs const in javascript?
If you're in an ES6 environment (i.e. Node or using Webpack/Babel for producing client-side code), then there's very little reason to use var. Use const when you won't be reassigning the variable, and use let when you will. More on reddit.com
🌐 r/learnprogramming
17
5
April 18, 2019
🌐
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.
🌐
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.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Statements › let
let - JavaScript - MDN Web Docs
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 ...
Find elsewhere
🌐
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.
🌐
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.
🌐
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 › javascript-scene › javascript-es6-var-let-or-const-ba58b8dcde75
JavaScript ES6+: var, let, or const? | by Eric Elliott | JavaScript Scene | Medium
August 30, 2025 - In JavaScript, `const` means that the identifier can’t be reassigned. (Not to be confused with immutable values. Unlike true immutable datatypes such as those produced by Immutable.js and Mori, a `const` object can have properties mutated.) If I don’t need to reassign, `const` is my default choice over `let` because I want the usage to be as clear as possible in the code. I use `let` when I need to reassign a variable.
🌐
CodeParrot
codeparrot.ai › blogs › javascript-var-vs-let-vs-const
JavaScript Var vs Let vs Const: Key Differences & Best Uses
September 1, 2024 - Helps reduce bugs by signaling variables intended to remain constant. Use let only when a variable's value needs to change. In modern javascript var vs let vs const , developers favor const and let over var for more predictable, maintainable, ...
🌐
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.
🌐
Fireship
fireship.dev › var-let-const
var vs let vs const in JavaScript
So to recap, var is function scoped ... const and let are blocked scoped and if you try to use variable declared with let or const before the declaration you'll get a ReferenceError. Finally the difference between let and const is that once you've assigned a value to const, you can't reassign it, but with let, you can...
🌐
Educative
educative.io › answers › difference-between-var-let-and-const-keyword-in-javascript
Difference between var, let, and const keyword in JavaScript
It is the traditional variable declaration in JavaScript. The var keyword was the only way to declare variables in JavaScript before ECMAScript 6 (ES6) was introduced in 2015. While still usable, var has some limitations compared to let and const.
🌐
Scaler
scaler.com › home › topics › javascript › difference between var, let, and const in javascript
Difference Between Var, Let, and Const in Javascript | Scaler Topics
June 21, 2024 - The main difference between Var, Let, and Const in JavaScript lies in their scope and mutability. Var is function-scoped and can be both re-declared and updated, making it the more flexible, yet potentially riskier option from older JavaScript ...
🌐
TecAdmin
tecadmin.net › what-is-var-let-and-const-in-javascript
Understand `var`, `let` and `const` Variables in JavaScript
February 17, 2021 - Hoisting: Similar to let, const declarations are hoisted but not initialized. Reassignment: A const variable cannot be reassigned or redeclared.
🌐
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 ...
🌐
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 ...
🌐
DEV Community
dev.to › chintanonweb › mastering-javascript-variables-a-deep-dive-into-let-var-and-const-866
Mastering JavaScript Variables: A Deep Dive into let, var, and const - DEV Community
April 23, 2024 - It's generally recommended to use let and const instead for clearer code semantics and better scoping. A: No, variables declared with const cannot be reassigned after initialization. However, for objects and arrays, you can modify their properties or elements without reassigning the variable itself. A: Hoisting is a JavaScript mechanism where variable and function declarations are moved to the top of their containing scope during compilation, regardless of where the actual declaration occurs within the code.