Created
September 4, 2017 17:14
-
-
Save csierra15/0706707569155d6ff2fbe0e426cf9850 to your computer and use it in GitHub Desktop.
In Your Own Words
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
What is scope? | |
Variable Scope | |
-Defines how a declared variable can or can not be accessed at different points in the code | |
-Global variable is accessible everywhere in the code, and is declared outside of a function. | |
-Block scope refers to how a variable is defined within a function and is only accessible within its function’s instructions. | |
-Global = outside a function; | |
Block = inside a function | |
***Global variable is untouched when Block variable is used/declared | |
-Scope chain is when JS looks inside a function to determine the value of a declared variable. If it’s not there, it will continue looking up the chain to determine to value of claimed variable. **side effects are not inherently a “bad thing.” | |
Why are global variables avoided? & What are side effects, and what is a pure function? | |
-Tend to cause unintended side effects: when a function reaches outside of local scope and further up into a parent scope to define a value. | |
-Global variables + unintended side effects = indeterminate code | |
-Determinate function: one that will always return same value | |
-Indeterminate function: returns different values; leads to buggy code | |
-Pure function: determinate w/ no side effects | |
Explain JavaScript’s strict mode. | |
-will raise an error if a variable is declared without a ‘let’ or ‘const’ | |
-‘use strict’; command at tope of code enforces strict mode for whole file, or at the top of a function to only apply it w/in a function | |
-best practice to use it at top of all JS files | |
-EXCEPTION to using global variables: when using JS library, like jQuery, jQuery applies $ global variable, and can be referenced in JS file. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment