Calling toString()
returns "[object Undefined]"
, while this.toString()
returns "[object Window]"
.
This is according to code run in Chrome 87 and Firefox 84.
My intuition dictates toString()
is the same as this.toString()
with this
part omitted, but the behaviour I'm seeing goes against this. What language feature of Javascript / ECMAScript governs this difference? Is it something special to toString()
?
The following code was used to check the behaviour of each browser. In IE 11 it was "[object Window]"
for all.
<html>
<head>
<script>
console.log("toString() = " + toString())
console.log("toString.call() = " + toString.call())
console.log("this.toString() = " + this.toString())
console.log("toString.call(this) = " + toString.call(this))
</script>
</head>
</html>