- Variables can be redeclared in the same block or scope.
- Variables declared with var keyword can be hoisted.
- Variables can not be redeclared in the same block or scope.
- Variables declared with the let keyword can not be hoisted.
- Can not access by the window object.
- Same as let can’t be redeclared in same block or scope and can not be accessed by the window object.
- Variables declared with as const have to assign value instantly and can not reassign other values to them later.
- If the const variable is an object or an array, we can add new array elements and object property values and update those values.
Strict Mode and ‘this’ Keyword
Constructor Functions and Classes
When we are creating objects using Constructor Functions, those functional classes have access to an object called Prototype. This object is conceptually similar to Java Object Class. The prototype is used to add methods and properties to constructor functions and to implement inheritance between functional classes. Only functional classes (like Person) have access to Prototype, not the objects (like p1).
A function that is being used to create an object, as shown above, is called the Constructor Function. We can implement inheritance between two functional classes as below.
We can implement the above scenario using the Class syntax, which is introduced in ES6. In the early days, it is not supported by many browsers. But now, the majority of browsers support Class syntax.
Callback and Promises
- But asynchronous operation introduces difficulty when we need to do synchronous processing using data.
- We use Callbacks and Promises to solve this problem.
- The callback is a function that is, being passed to an async task, and on completion, the function will be executed.
- A promise is an object that is being returned from async tasks. Promise has properties to deal with async operations synchronously.
🔸 To do intensive synchronous processing using data, sometimes we have to pass a lot of nested callbacks to a sequence of an asynchronous task; this is called Callback Hell. To solve this problem, we use promise objects. Promise objects have properties and methods to handle complex nested callbacks nicely.