Advertisement
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. block scope.
- Answer: Scope determines the accessibility (visibility) of variables. In JavaScript there are two types of scope (Local, Global Scopes).
- Variables defined inside a function are not accessible (visible) from outside the function. Variables declared within a JavaScript function, become LOCAL to the function.
- Local variables have function scope, they can only be accessed from within the function.A variable declared outside a function, becomes GLOBAL.
- A global variable has global scope, all scripts and functions on a web page can access it.
- Why are global variables avoided?
- Answer: Global variable are avoided because they can create bugs.It will make the application hard to maintain and read.
- Looking for global variables just to know how they were created or manipulated will take some time.
- Explain JavaScript's strict mode
- Answer: It helps with writing a cleaner code, and prevents you from using undeclared variables.
- Strict mode is declared by adding "use strict"; to the beginning of a script or a function.
- Strict mode makes it easier to write βsecureβ JavaScript.
- What are side effects, and what is a pure function?
- Answer: A side effect is when a function reaches outside its local scope up into a parent scope and alters a value that lives there.
- 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