Last active
October 16, 2019 05:21
-
-
Save challey17/7325117e1279aa674c979d514bc06cdb to your computer and use it in GitHub Desktop.
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? | |
"Scope" describes the the scope and limitations of impact that a variable can have on the overall code and program. The scope of a variable is | |
dependent on how and where it is defined or declared. A variable defined outside a fucntion will have "global scope" and can effect | |
the entire program; a variable defined within a function will have "block scope" and will be limited to it's particular block of code. | |
Why are global variables avoided? | |
A variable with "global scope" can effect the entire program whereas a variable | |
with "block scope" is contained within it's particular block of code, so can be controlled more specifically. "Block scope" | |
variables are generally preferred because of their higher predictability and also the coherence of the entire code. | |
Explain JavaScript's strict mode. | |
"Strict Mode" is a clever way to address the potential problem of variable scope. By sending the command: 'use strict'; to the | |
JavaScript engine at the beginning of a file, the JavaScript interpreter will only accept variables defined with 'let' and | |
'const' to ensure more clarity and less errors. If a variable is defined without using 'let' or 'const' and error will be triggered. Strict mode can also be | |
applied solely within a function itself, intstead of the entire document. | |
What are side effects, and what is a pure function? | |
A side effect of a function is the effect that function has outside of it's own local scope, outside of it's on block of code. | |
A pure function is a function that is determinate, meanining it always produces the same results given the same input. A pure | |
function also does not create unintented side effects, meaning it does not effect the overall code and program unless it is clearly | |
meant to do so. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment