[TypeScript] Let vs Const vs Var

When to use each of these?

FAM
The Startup

--

All have started with var…

Plain Javascript has only a var keyword that allows you to define a variable.

Here is an example of how we can use it:

Will the last line of code passe or fail?

Well, there is no problem with the code since the var keyword is not block-scoped. This means there is no scope for variables that are declared with var, whether they are declared inside or outside of a loop or a condition.

To resolve this problem, you need to declare you variable with let or const.

‘Let’ comes to solve the issue

The let statement declares a block-scoped local variable, optionally initializing it to a value.

--

--

FAM
The Startup

A passionate software engineer and Angular GDE. I love to learn, help & share ❤. Find more about me here: 🔗 www.fatimaamzil.com.