Home » JavaScript OOPs Abstraction

JavaScript OOPs Abstraction

by Online Tutorials Library

JavaScript Abstraction

An abstraction is a way of hiding the implementation details and showing only the functionality to the users. In other words, it ignores the irrelevant details and shows only the required one.

Points to remember

  • We cannot create an instance of Abstract Class.
  • It reduces the duplication of code.

JavaScript Abstraction Example

Example 1

Let’s check whether we can create an instance of Abstract class or not.

JavaScript OOPs Abstraction

Example 2

Let’s see an example to achieve abstraction.

Test it Now

Output:

Vehicle is: Honda 

Example 3

In this example, we use instanceof operator to test whether the object refers to the corresponding class.

Test it Now

Output:

true true 
Next Topic#

You may also like