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 ukhlivanov/4c364ace4d01b2ce6aa35ef5413e7510 to your computer and use it in GitHub Desktop.
Save ukhlivanov/4c364ace4d01b2ce6aa35ef5413e7510 to your computer and use it in GitHub Desktop.
Scope and Variables
What is scope? Your explanation should include the idea of global vs. local scope.
Scope refers to the visibility of variables. Global variable will be avialable everywhere in program. The local variable will only be available in the code block where it was defined (for example: class or function). When you define a variable in a function that has the same name as a variable in the global scope, the local variable will take precedence over the global one.
Why are global variables avoided?
Global variables are hard to use together with other developers. A global variable can be changed to any part of the program and therefore it is difficult to control it especially in a large application.
Explain JavaScript's strict mode.
When strict mode is enabled all variables should be declared(for example let myVar="myVar"), for variables without declaration error will be triggered. The command "use strict" can be put at the top of file to enforce strict mode, or at the top of functionб, in this case, strict mode will only work for function. Best practice is using strict mode as a default mode.
What are side effects, and what is a pure function?
A function is said to be pure when it is both determinate and has no side effects.
A side effect is when a function reaches outside its local scope up into a parent scope and alters a value that lives there.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment