Created
April 7, 2017 16:03
-
-
Save tian-chaiyaporn/4c8229f3403991fee71cd0a2f1b6b779 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? | |
Ans: Scope refers to the level of code block in a code file. It usually is used to differentiate the global scope and local scope; | |
The global scope refers to the whole code file, while the local scopr refers to the code block within individual functions. | |
Why are global variables avoided? | |
Ans: Global variables are usually avoided to prevent unexpected mutations of global variables that can happen unintentionally in large projects. | |
Explain javascript 'strict mode' | |
Ans: Javascript strict mode prevents potenrially dangerous actions such as the creation of variables without the 'var' declaration. | |
What are side effects? What are pure functions? | |
Ans: Side effects refer to unintended mutation of functions or variables. Pure functions are not mutable and therefore always produces the same result which only depends on its arguments. | |
Explain variable hoisting in Javascript | |
Ans: Variable hoisting is the way the web reads JavaScript file. It first reads through the whole file to see what functions are available and what variables are declared and assign 'undefined' to them. | |
Once it has checked the variables and match them up without errors to the rest of the files, then it goes through the JavaScript file again in detail from top to bottom. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@tian-chaiyaporn one bad thing that happen when you don't use
var
(orlet
/const
which was introduced in ES6) to create variables is that it will automatically be created in the global scope, possibly causing a lot of maintainability issues.