Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1. What is scope? Your explanation should include the idea of global vs. block scope.
- scope is the environment in which items like objects and functions are available. block scope, for example,
- is the environment within a block, such as a for loop, a function, or an object. in block scope, variables are
- considered 'local'. global scope is the environment that contains everything that wasn't declared inside of
- a block. in vanilla js, this is typically the window object.
- 2. Why are global variables avoided?
- global variables are avoided mainly because they can cause collisions, such as name conflicts with external resources,
- other scripts, window properties, etc. they're also avoided because they're technically slower to reference than local
- variables.
- 3. Explain JavaScript's strict mode
- in strict mode, many things are changed to prevent certain behaviors. for example, if a variable is declared without
- any variable keyword (like let, const, or var) in non-strict mode, that variable becomes a property in global namespace.
- however, in strict mode, doing this just throws an error. also, assigning values to non-writable items like NaN (which just
- fails silently in non-strict) throws an error. strict mode has many, many other features as well, mainly meant to prohibit
- illegal / discourages practices in javascript.
- 4. What are side effects, and what is a pure function?
- side effects are unintended behaviors of a script, usually as a result of mistakes that were made in writing: such as a function
- modifying objects outside of its scope that it isn't meant to access.
- a pure function has no side effects, and also always provides x output for y input every time it is called. an example of
- a typical pure function would be a hashing algorithm.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement