Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Scope is the accessibility of variables. It is based on the variables available in a file(s). There are two types of scope, global and local.
- A variable that is declared outside of a function body and that can be accessed and modified across files has global scope. Local scope
- refers to a variable that is only accessible within a function. Global variables are to be avoided because it can create buggy code. It
- could cause unintentional side effects and change/ alter the physical outcome of your code. Javascript has a command called ‘strict mode’
- to account for any variables that are declared without the var keyword. It helps to avoid code that is hard to debug. A side effect is the
- result of a function that reaches outside of its local scope by accessing a global variable. This may cause an intended change, but may
- also cause an unintended change, which may return a different value than intended. On the other hand, a pure function is a function free
- of side effects and will always return the same value. To hoist means to raise up. In the context of JavaScript, hoisting is the behavior
- in which variables and function declarations are processed before any code is executed. Basically, no matter where a variable is declared,
- it will equate to declaring it at the top of its scope.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement