Last active
October 22, 2016 08:59
-
-
Save CodeSigils/32873be8f9a5141f46b37f562aee8b74 to your computer and use it in GitHub Desktop.
Challenge: 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
Q: Why are global variables avoided? | |
A: Because their values can be overwritten by the values of local variables. | |
Local scope (function scope) can have access to global scope. | |
Sometimes this can be useful like when we want global access to a library | |
like JQuery in all our files. Or we want a function to have access in a database. | |
Q: Explain JavaScript's strict mode | |
A: When 'strict mode' is enabled declaring a variable without the var keyword, will rise an error. | |
The 'use strict' command can be put at the top of a file to enforce strict mode for the entire file. | |
Q: What are side effects, and what is a pure function? | |
A: Global variables tend to make side effects in a program. A side effect is when a function reaches | |
outside its local scope, up into a parent scope (bacause of scope chaining) and alters its value. | |
A pure function is a function where the return value is only determined by its input values, | |
without side effects. | |
Q: Explain variable hoisting in JavaScript | |
A: Hoisting is the JavaScript interpreter’s action of moving all variable | |
and function declarations to the top of the current scope. | |
However, only the actual declarations are hoisted. Asignments are left where they are. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment