Local Scope allow access to everything within the boundaries (inside the box)
Global Scope is everything outside the boundaries (outside the box). A global scope can not access a variable defined in local scope because it is enclosed from the outer world, except if you return it.
2. IIFE (Immediately Invoked Function Expression)
A closure is simply a function inside another function that has access to the outer function variable. Now, this definition sound pretty much straightforward but the real magic is created with the scope. The inner function (closure) can access the variable defined in its scope (variables defined between its curly brackets), in the scope of its parent function, and the global variables. Now here you need to remember that the outer function can not have access to the inner function variable.
A promise may be in three possible states…
Fulfilled: When the operation is completed successfully.
Rejected: When the operation is failed.
Pending: initial state, neither fulfilled nor rejected.
7. Async & Await
ES5 -> Callback
ES6 -> Promise
ES7 -> async & await
8. Error handling, “try…catch”
The try…catch statement marks a block of statements to try and a block of statement to catch errors if an exception is thrown.
The try block contains one or more statements enclosed by brackets. The catch block also contains one or more statements enclosed by brackets that specify what to do if an exception is thrown in the try block. If any statement within the try block throws an exception, control immediately shifts to the catch block. If no exception is thrown in the try block, the catch block is skipped.
9. Cross Browser Testing
Functions with Default Parameter Values. Default function parameters allow named parameters to be initialized with default values if no value or undefined is passed.
Arrow Functions. There’s another very simple and concise syntax for creating functions, that’s often better than Function Expressions. It’s called “arrow functions”, because it looks like this:
let func = (arg1, arg2, …, argN) => expression
Multiline arrow functions. The examples above took arguments from the left of
=> and evaluated the right-side expression with them. Sometimes we need something a little bit more complex, like multiple expressions or statements. It is also possible, but we should enclose them in curly braces. Then use a normal return within them. Like this: