When we declare any variable using var
keyword , it is function scoped. It means that, the variable can be accessed within the function. This leads to wrap the code in a function whenever we need to create a new scope. But let
and const
keywords uses block scoping. This means the variable declared using these keywords only exist within the innermost block that surrounds them.