Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js get class from instance

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: #js #class #instance
ADD COMMENT
Topic
Name
3+2 =