var declaration is function scoped and let declaration is block scoped.
See https://basarat.gitbook.io/typescript/future-javascript/let for more details.
Answer from MartyIX on Stack OverflowTutorial Teacher
tutorialsteacher.com › typescript › typescript-variable
TypeScript Variable Declarations: var, let, const
... The let declarations follow the same syntax as var declarations. Unlike variables declared with var, variables declared with let have a block-scope. This means that the scope of let variables is limited to their containing block, e.g.
Top answer 1 of 5
102
var declaration is function scoped and let declaration is block scoped.
See https://basarat.gitbook.io/typescript/future-javascript/let for more details.
2 of 5
45
example:
// demo: var
for(var i =0; i<5; i++){
console.log(i)
}//finally i =5
console.log(i) // i=5
// demo: let
for(let i = 0; i<5; i++){
console.log(i)
}
console.log(i)// i is undefined
Videos
r/ProgrammerHumor on Reddit: me before I learned the difference ...
08:37
Differences Between Var, Let, and Const - YouTube
04:15
Var vs Let vs Const: Choosing the Right Variable in JavaScrip - ...
08:48
var, let, and const: What is the Big Difference! - YouTube
10:56
Difference between let and var | Variables | JavaScript - YouTube
04:27
var, const, let... now ‘using’? - YouTube
What are the main differences between var and let in JavaScript?
The main differences lie in their iterations, scope, access, declaration, and re-declaration. For example, the var keyword has a global scope, while the let keyword is limited to block scope.
testbook.com
testbook.com › home › key differences › difference between var and let in javascript - testbook
Difference Between var and let in JavaScript - Testbook
What is the var keyword in JavaScript?
The var statement assists a user in declaring any variable in JavaScript. A variable declared with this keyword stays defined throughout a given program.
testbook.com
testbook.com › home › key differences › difference between var and let in javascript - testbook
Difference Between var and let in JavaScript - Testbook
What is the let keyword in JavaScript?
The let statement assists a user in declaring any local variable in TypeScript. The var keyword is similar to the let keyword, but there are some restrictions in the let keyword as compared to the var keyword.
testbook.com
testbook.com › home › key differences › difference between var and let in javascript - testbook
Difference Between var and let in JavaScript - Testbook
TypeScript
typescriptlang.org › docs › handbook › variable-declarations.html
TypeScript: Documentation - Variable Declaration
In other words, they have the same scoping rules as let, but you can’t re-assign to them. This should not be confused with the idea that the values they refer to are immutable. ... Unless you take specific measures to avoid it, the internal state of a const variable is still modifiable. Fortunately, TypeScript allows you to specify that members of an object are readonly.
Reddit
reddit.com › r/typescript › var, const, let
r/typescript on Reddit: var, const, let
April 24, 2018 -
I confuse the following term var, const, let in typeScript and when should I use them?
Top answer 1 of 4
34
Rule of thumb: start with const, if you need to change the value later, change to let, and forget about var.
2 of 4
17
let - use this when you are declaring a variable to be used in a scope and possibly re-assigned later. const - use this when you know you never need to re-assign to the variable. assign when you declare and never again. var - don't use this. it's old and pointless. That's it!
Tektutorialshub
tektutorialshub.com › home › typescript › typescript let vs var vs const
Typescript Let vs Var vs Const - Tektutorialshub
March 15, 2023 - The following example shows how to declare a variable using the above keywords. You can learn more about the variable declaration from Typescript variables tutorial. There are four ways you can declare a variable. They are ... Use var and let to define any variable, with or without type or initial value.
Mimo
mimo.org › glossary › typescript › let
TypeScript Let: Syntax, Usage, and Examples
Use let in TypeScript to declare block-scoped, mutable variables. It’s ideal when values change—safer and more predictable than var.
GeeksforGeeks
geeksforgeeks.org › javascript › difference-between-var-and-let-in-javascript
Difference between var and let in JavaScript - GeeksforGeeks
Code 2: In the following code, clicking start will call a function that changes the color of the two headings every 0.5sec. The color of the first heading is stored in a var and the second one is declared by using let. Both of them are then accessed outside the function block.
Published July 11, 2025
Mimo
mimo.org › glossary › typescript › var
TypeScript Var: Syntax, Usage, and Examples
Because var is function-scoped, not block-scoped, the variable i isn’t reset on each loop iteration. This causes all callbacks to log 3, not 0, 1, and 2. You can fix this by using let instead. When you use var, TypeScript hoists the declaration (but not the initialization) to the top of the function or global scope.
Medium
medium.com › @iamsounak01 › understanding-let-const-and-var-in-typescript-a-beginners-guide-with-examples-e99ab6c6fc62
Understanding let, const, and var in TypeScript: A Beginner's Guide with Examples | by Sounak Das | Medium
November 8, 2024 - Explanation: In the example, var hoists the variable declaration to the top of the function, making it accessible before the line where it’s actually assigned. However, only the declaration is hoisted, not the assignment, so the first console.log returns undefined. let was introduced in ES6 to address some of the limitations of var.
www.java4coding.com
java4coding.com › contents › typescript › typescript-let-vs-var
TypeScript let vs var - java4coding
A variable declared with var has function scope. When declared in a function, the variable can be accessed everywhere in the function. A variable declared with let or const has block scope.
W3Schools Blog
w3schools.blog › home › difference between var and let
Difference between var and let - W3schools
February 27, 2018 - The var statement is used to declare a variable. We can optionally initialize the value of that variable. Example: var num =10; The let statement is used to declare a local variable in a block scope. It is similar to var, in that we can optionally initialize the variable.
Codecademy Forums
discuss.codecademy.com › frequently asked questions › javascript faq
What are the differences between `var` and `let`? Are they necessary?
May 6, 2019 - When creating a variable, do you need to use let or var at all if the variable ISN’T going to be a constant? The code still seems to record the variable just fine, and allow changes, whether I use var/let or not. ? Same with spaces between the +, -, / etc. The code seems to work just fine ...