Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tian-chaiyaporn/4c8229f3403991fee71cd0a2f1b6b779 to your computer and use it in GitHub Desktop.
Save tian-chaiyaporn/4c8229f3403991fee71cd0a2f1b6b779 to your computer and use it in GitHub Desktop.
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.
@joeljuca
Copy link

joeljuca commented Apr 8, 2017

@tian-chaiyaporn one bad thing that happen when you don't use var (or let/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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment