Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Get Class Name from an Object Instance in JavaScript</title> </head> <body> <script> class Rectangle { // Class constructor constructor(length, width) { this.length = length; this.width = width; } // Class method getArea() { return this.length * this.width; } } var rectObj = new Rectangle(5, 10); document.write(rectObj.getArea() + "<br>"); // Prints: 50 document.write(rectObj.constructor.name) // Prints: Rectangle </script> </body> </html>