javascript - what's different between Object.prototype.toString.call and typeof -


i'm noob of javascript , i'm confused what's difference following methods.

function foo(){}; var bar = new object();  object.prototype.tostring.call(foo).slice(8, -1);    // output "function" typeof foo;                                          // output "function"  object.prototype.tostring.call(bar).slice(8, -1);    // output "object" typeof bar;                                          // output "object" 

you can't override gets returned typeof

var myobject = function() { };  myobject.prototype.tostring = function() { return undefined; }  var x = new myobject();    console.log(typeof x);  console.log(x.tostring());

if you're interested in javascript`s methods, check out mdn:

mdn typeof

mdn tostring


Comments