How to print only the `this` object's name , and not it's contents in javascript?

  • A+
Category:Languages

consider the function:

function foo() {   console.log(this); }  foo();

How to print only the this object's name (window or global....etc), and not it's contents?

 


You can print an objects name in js with obj.constructor.name.

function foo() {   console.log(this.constructor.name) }  foo()

Will print Window

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: