JavaScript supports var
, let
, const
to define variables.
However, you had better not to use var
.
The reason is that
So, you should use let
instead of var
for rewritable variables. And you should use const
for constant variables.
var hello = 'hello'
if (true) {
var hello = 'world'
console.log(hello)
}
console.log(hello)