Skip to content

Instantly share code, notes, and snippets.

@benfletcher
Last active October 25, 2016 03:33
Show Gist options
  • Save benfletcher/f6e34629a43fa057fcf605a4410d2f52 to your computer and use it in GitHub Desktop.
Save benfletcher/f6e34629a43fa057fcf605a4410d2f52 to your computer and use it in GitHub Desktop.

Questions

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

    Scope is the concept of where a variable can be accessed. Variables should usually be created within the scope of a function instead of being created as properties of the global object ('window' in the browser). A local variable is one that has been declared in the context of the current function.

  • Why are global variables avoided?

    Global variables create many problems including unintended consequences and incompatibilities between libraries or files. They also make finding errors more difficult because it's harder to narrow down the source of some problems.

  • Explain JavaScript's strict mode

    Strict mode was added to Javascript with ES5 as a way to reduce the impact of certain weaknesses of the language. With regard to variables, strict mode changes the default behavior of making an undeclared variable a global.

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

    A pure function is one that has zero side effects and is deterministic, meaning it will always return the same value for any particular set of input. It does not depend on the state of nor existence of any variables or conditions except those explicitly passed in as parameters. It does not change the state of any external variable.

  • Explain variable hoisting in JavaScript.

    Variable declarations and function definitions are moved to the top of the scope in which they are found. Assignments made within a variable declaration are not moved along with the declaration, however, function definitions are.

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