I'm confused with Javascript's prototype property. See the below Code.
var s = 12;
var s1 = new String();
console.log(s.constructor); // Outputs: Number() { [native code] }
console.log(s instanceof String); // Outputs: false
console.log(s instanceof Object); // Outputs: false
//console.log(toString() in s);
console.log(s.isPrototypeOf(Object)); // Outputs: false
//console.log(s.prototype.isPrototypeOf(Object));
console.log(s.hasOwnProperty ("toString")); // Outputs: false
console.log(s.toString()); // // Outputs: 12
// My Question is how does toString() function is been called, where does it falls int the prototype chain. Why is it not showing undefined.
console.log(s1.constructor); // Outputs: Number() { [native code] }
console.log(s1 instanceof String); // Outputs: true
I understand that when we create an object by using {} or constructor (new String()) above, it inherits from Object.prototype. And thats why console.log(s1 instanceof String); // Outputs: true and thus we're able to call toString() on s1. But i'm confused with what happens in the case of var x = "someString" or var x = something.
Thanks for your time.