Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. Scope is an idea that you have to understand as a developer in order to comprehend how your code works and avoids bugs. For example, for code using let and const, there are 2 kinds of scope to understand: global and block. When you declare a variable in the global scope, it is available everywhere in your code. Any variable that is declared outside of a function in javascript has global scope. On the other hand block scope is only accessible within the function's block of instructions.
  2. Global variables are avoided because they tend to make unintended side effects. Sometimes it can be a good thing but the problem is when the side effect is unintended which could cause some problems/bugs in your code. Which is why they should be avoided and a function should be pure and determinate unless its meant to have side effects.
  3. When strict mode is enabled, any time a variable is declared without the let or const keyword, an error will be triggered. If you want enforce strict mode for the entire file then the 'use strict' command can be put at the top of a file. Or it can be put at the top of a function, if you only want to use strict mode within the body function.
  4. A side effect is when a function reaches outside its local scope up into a parent scope and alters a value that lives there. Sometimes they are good but can also lead to frustrating bugs in code. A function is said to be pure when it is both determinate and has no side effects.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement