Guest User

Untitled

a guest
Jan 17th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. Scopes are essential in javascript. There are two types of scopes global and local. A global scope is a variable that is set outside a function and the value of this variable can be manipulated throughout the program. A local scope is a variable that is set inside of a function which can only be used in that function and no where else. A local variable however can have the same name as a global variable set outside the function but it is a seperate variable and has no effect on the global varaiable. Variables with global scopes are avoidable because they can be read and manipulated which can lead to the variable changing. This can lead to code errors because if one function manipulated the variable and modified it another function might need the original variable in it but since it has been changed globally the new function will be getting the wrong data.
  2. In normal javascript mistyping a variable name can create a new global variable however in strict mode mistyping will lead to an error and it would be impossible to create a new global variable. Using a variable/object without declaring it is not allowed as well in strict mode. A pure function is a function in which given the same input it will always return the same output and will produce no side effects. Functions with side effects do something other than just returninga value. Side effects are essentially an event that occurs when a function manipulates value out of its scope that was being used globally.
Add Comment
Please, Sign In to add comment