Languages

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

4 points
Asked by:
Marcin
2465

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

1 answers
1 points
Answered by:
Marcin
2465

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
Hey ūüĎč
Would you like to know what we do?
  • Dirask is a friendly IT community for learners, professionals and hobbyists to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.