ES6: var vs let vs const

Dealing with KnockoutJS I came across some newer features of the JavaScript language ES6

TL;DR: don’t use var anymore when You declare variables.

Some examples:

As You can see a variable declared with the var keyword is visible outside its enclosing scope. Most of the time it’s not what You want.

When You enable ES6 support in PyCharm it already warns You if You use var:

To declared a variable which is on visible in its scope You can either use let or const.

Let lets your variable be mutable so you can use it in a loop as counter. If You want to guarantee even more that one variable is used for one concept only You can use const which makes the variable immutable.