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

4 points
Asked by:

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:


  • 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:

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.