Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

get class name object

class Language {}

const l1 = new Language();

console.log(l1.constructor.name); //Language


// Works too
(1)?.constructor.name // "Number"
(false)?.constructor.name // "Boolean"
(1)?.constructor.name // "Number"
("aa")?.constructor.name // "String"
([])?.constructor.name // "Array"
({a:"a"})?.constructor.name // "Object"
(false)?.constructor.name // "Boolean"
(null)?.constructor.name // undefined
(document)?.constructor.name // "HTMLDocument"
(myImageElement)?.constructor.name // "HTMLImageElement"
Source by itsjavascript.com #
 
PREVIOUS NEXT
Tagged: #class #object
ADD COMMENT
Topic
Name
8+2 =