The scope of a variable controls where it can be accessed from in the program. It can be of
- Global Scope
- Function scope
- Block scope ( if / for etc )
Variables can be defined with
varkeyword is function scoped
constkeyword are block scoped.
- Different from how other languages use this.
- In JS land, value of this depends on how a function is called.
applyhelps in setting correct
- the difference is in the way the arguments are provided
applytakes a array of arguments whereas
calltakes in individual arguments.
- All variable declarations are hoisted on the top of their scope.
- Hence they are processed before the code gets executed.
varis set as undefined and can be accessed before declaration.
constcannot be accessed and throws a referenceError if tried.