Differentiate between ES6 class and ES5 function constructors.
ES6 class | ES5 Function Constructors |
---|---|
ES6 class basically does the work of defining a new object and appending functions to its prototype. | ES5 Function constructors work and look the same but the main difference is observed when the developer uses the Inheritance property. |
They can be considered as the syntax base for constructor functions. | These can only be executed with the help of a new operator. |
ES6 class allows the developers to instantiate objects using the new operator. | ES5 function constructors focus on how the objects are instantiated. |
They also ensure the developer that this keyword which is basically used inside the class only refers to the object that is being created by the developer. | ES5 function constructor focus on implementing the reusable object creation code. Any function can be used as a constructor. |
BY Best Interview Question ON 06 Oct 2019