Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- What is scope? Your explanation should include the idea of global vs. local scope.
- Why are global variables avoided?
- Explain JavaScript's strict mode
- What are side effects, and what is a pure function?
- "Scope" refers to the visibility of variables, which means if your variable can be accessed by different parts of your code or
- just within a function's block. Variables can either have a "global" or "local" scope. Variables which are declared outside of a
- functions block are automatically created in the "global scope". As well as variables which are declared without "let" or "const"
- keyword. Now "local scope" variables are those which are declared within a function, which means that they can only be accessed
- within that function. Global scopes are to be avoided and that is because they can create unintended consequences elsewhere in
- your code or when you try to run your function again. For this reason, you should always declare your variables within a function
- as well as using the keywords, "let" and "const". To avoid accidentally declaring variables you should take advantage of JavaScript's
- "use strict;" mode. Strict mode will alert you at any time a variable is declared without the let or const, an error will be triggered.
- So you can avoid any more bugs in your code you should also strive to make your functions "pure". This means that your function is both
- determinate and has no effects outside that functions block.
Add Comment
Please, Sign In to add comment