Created
October 2, 2019 17:58
-
-
Save gusmcnair/02e77086a062cbf72fb804f44d45ac1b to your computer and use it in GitHub Desktop.
Variable scope questions and answers
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? Your explanation should include the idea of global vs. block scope. | |
Scope describes where and when a variable can be accessed in code. | |
Global scope is available anywhere in the code, whereas block is only available in a specific function or situation. | |
Why are global variables avoided? | |
Global variables can cause functions to be indeterminate, which means that they can have the same input and produce different results. | |
They can also cause code to behave in unexpected ways and make debugging difficult. | |
Explain JavaScript's strict mode | |
Strict mode does not allow global variables (eg, "dog = 123") and forces one to use var, let or const. | |
What are side effects, and what is a pure function? | |
A side effect is when a function affects something outside its own scope, and in its parent scope. | |
A pure function is one that is determinate (same input always produces same output) and has no side effects. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment