Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. Scope is the set of rules that determine whether the code you are working on has access to the variables and their assigned values. If a variable is in the current scope of the code, it is accessible. If it is not in the current scope of the code, it is unusable and will cause errors. Global scope describes a variable that has been declared outside a local function. A variable with global scope can be used anywhere in your code, not just locally. Global variables should be avoided, because sometimes global scope creates problems for co-programmers who both designate the same variable but with different values or jobs. This can cause bugs and breaks in the code. Global scope is different from block scope. Block scope provides rules for the variable that are only available within that particular function. Block scope can be thought of as local, or code that can only function on your local neighborhood block so-to-speak.
  2. One way to help alleviate problems with variable scope is to use JavaScript's strict mode. By typing 'use strict' at the top of your JavaScript page, it allows strict rule enforcement in your js files. It requires that the keywords let and const are used when declaring variables. Using strict mode can help with harmful coding side effects that may occur when defining duplicate variables. Scope chain heirarchy will look to see how a duplicated variable should be interpreted and sometimes will assign an indeterminate value which leads to inconsistent returns and bugs in your code. When working on large projects, side effects can become very harmful and hard to fix. It is best to keep code to its purest form. That is, keep it determinate without causing any harmful side effects, where it has consistent results and returns when given the same input values.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement