Skip to content

Instantly share code, notes, and snippets.

@jcharles22
Created February 21, 2019 04:28
Show Gist options
  • Save jcharles22/87200b00901d0582e02c73a2b2cc6afe to your computer and use it in GitHub Desktop.
Save jcharles22/87200b00901d0582e02c73a2b2cc6afe to your computer and use it in GitHub Desktop.
What is scope? Your explanation should include the idea of global vs. block scope.
Scope is the accessibility of the variables you create to different places in your code. You have global and block scope if you create a variable in the global scope it is being declared outside of any function. Block scope variables are declared with-in a function and they can only be accessed in that function or functions nested in that one.
Why are global variables avoided?
Global variables are avoided because, they can be accessed and changed from anywhere. Making it easy for your code to have errors. Also, it makes your code harder to read. Global variables can even be accessed from different files as long as the file gets loaded before the variable gets called.
Explain JavaScript's strict mode
JavaScript’s strict mode checks your code and throws error when some conditions are met where other times no error would be thrown. Such as anytime you declare a variable without let or const, an error will be triggered. To enable it all you have to do is add 'use strict'; at the top of the file.
What are side effects, and what is a pure function?
A side effect is when a function goes up the scope chain and alters a value in a parent scope. This can cause some functions to give you different values then you intended with the same input. For that reason side effects can make it very tricky to track down bugs in your code. Pure function is one that will always give you the same value if provided with the same input, without modifying any data outside its scope. Unless the function are specifically meant to.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment