Skip to content

Instantly share code, notes, and snippets.

@johnayoung
Last active October 29, 2018 17:33
Show Gist options
  • Save johnayoung/e5d62966b3f1f1c4a156ba5c5ce09465 to your computer and use it in GitHub Desktop.
Save johnayoung/e5d62966b3f1f1c4a156ba5c5ce09465 to your computer and use it in GitHub Desktop.

What is scope? Your explanation should include the idea of global vs. local scope.

Scope determines the level at which variables can be accessed and modified. Scope is determined by the scope chain, which is the standard for determining the scope of variables.

Local scope refers to the lowest level of the scope chain, and typically refers to block level (ie, inside levels of a function. Global scope refers to the highest level of the scope chain, and can be accessed across not only the current file, but all files across the app.

Why are global variables avoided?

Global scope has the tendency to increase the likelihood of unintended side effects in code. Unintended side effects can make code error-prone and more difficult to debug.

Explain JavaScript's strict mode

Strict mode (which can be placed globally or scoped inside of functions) prevents the usage of variables that did not use let or const.

What are side effects, and what is a pure function?

Side effects are when functions reach out of their scope into parent (or global) scope and change the values.

A pure function is one that is determinate (ie, always returns the same value when provided with the same inputs) and has no side effects.

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