JavaScript Abstraction

Abstraction is a way of hiding complexity. The JavaScript Data Abstraction feature is used for hiding internal details and showing the essential features of the object only.

Note: We can not instantiate the Abstract class.

Example:

<!DOCTYPE html>
<html>
<body>
<script>
function Student()
{
this.Name="Name";
throw new Error("You cannot create an instance of Abstract Class");
}
Student.prototype.print=function()
{
return "Student is: "+this.Name;
}
function KG(Name)
{
this.Name=Name;
}
KG.prototype=Object.create(Student.prototype);
var kg=new KG("Vivek");
document.writeln(kg.print());
</script>
</body>
</html>