JavaScript scope, hoisting, and let vs var vs const

12/7/20

js

What is scope?

Scope means where the variables are available to be used. Scope can either be globally and so it can be accessed from anywhere or locally so only within the function in which the variable is created.

What is Hoisting?

Hoisting is the process in-which a variable that is declared is pulled before a function is run. This could cause some problems as occasionally position really matters and so a variable may read undefined if it gets hoisted.

In what cases would you use let vs const vs var?

Const is used when the programmer doesn’t want that value to be changed at any point, it keeps the value assigned consistent. Let is used in place of var when in a block of code as it doesn’t get hoisted and therefore is easier to work with then var. Var is used outside of functions, usually as a global variable.

Helpful Video

IMAGE ALT TEXT HERE