Hoisting

In JavaScript, hoisting refers to the behavior where variable and function declarations (but not initializations) are conceptually moved to the top of their scope (function or global) during the compilation phase.!

var

Has function-level or global scope. This means a variable declared with var is accessible throughout the entire function it's declared in, or even globally if declared outside of any function.

let and const keywords were introduced in ES2015 or ECMAS-6, before this variables were used to be declared only with var.