Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- What is scope of a variable:
- Scope is the cumulative extent of a program or application. It includes the variables and functions within the defined parent, whether that be a function or application. a variable's scope will allow the varibale to be called withi a whole file or just within the function for which it is called; Most notably, it includes what can be referenced and what is unable for a function or other to call.
- Why are global variables avoided:
- Global variables are avoided becuase they cuase the code to be indeterminate. A function may produce differing results with various inputed parameters.
- Javascript's Strict Mode:
- Strict mode is a way to make global variables more reliable or determinate. Strict Mode requires the variables to be explicitly named. Strict Mode will throw erros when a referenced variable is not consistent with a variable in existence.
- Strict Mode does not accept bad syntax and requires the contributors to adhere to the current standards being utilized within the project.
- Strict mode has the opportunity to be called within the script's file, enforcing the entire scope of the items within the file.
- Script mode also has the opportunity to be called within a function, requiring that the variable's defined within the function can not be used outside of that strict function. Make sure to declare variables before I call them.
- Side Effects:
- unintended results from a variable or function reaching outside of the local scope of that element. It may reach to a parent element, tracing back information and elements defined in other locations of the project. Ultimately, if may make a function unreliable. While the strict will limit, side effects are due to non-limitations.
- Pure Function:
- a pure function would not affect a global variable. only deals with and returns data within the local scope.
- Hoisting:
- hoisting refers to the way the javascript renders variables when it is parsing and executing; In order to udnerstand hoisting, one must understand the order in which a browser would read a script file. Javascript first reads the variables defined throughout a scope. It would then read through the functions and save memory for which. Functions and variables which are defined within a function, can only be used by calling that parent function.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement