Languages

JavaScript - what is the difference between var and let keywords?

4 points
Asked by:
Marcin
15740

In JavaScript when should I use var and when let?
What are the pros and cons?
I would appreciate code examples.

1 answer
1 points
Answered by:
Marcin
15740

Difference:

  • let keyword varialbes do not have varialble hoisting
  • let variable can be created in bracket scope and is removed after scope ends, var variable too, but is available still after the scope, e.g. for (let i = 0; ... creates i variable for loop only.

That article describes difference better:

https://dirask.com/posts/JavaScript-what-is-the-difference-between-let-and-var-ZpaZkj

0 comments Add comment
Native Advertising
50 000 ad impressions - 449$
🚀
Get your tech brand or product in front of software developers.
For more information contact us:
Red dot
Dirask - friendly IT community for everyone.

❤️💻 🙂

Join