In the below code :-
var x = { } ;
console.log(typeof x); // o/p is object
console.log(x instanceof Object ); //o/p is true
If I use “object” instead of “Object” in the last line I get an error.Why is that so when the o/p of second line is object with a lowercase “o”?
Because there’s no such thing as an ‘object’. Typeof doesn’t give you the class back – it gives you back the primitive type that it is. For example,
typeof "string"gives you back “string”.The ‘Object’ is a constructor for an object ‘primitive’ – so a
new Objectgives you back an ‘object’ to work with.. but don’t expect to be able to create a ‘new object’, as an ‘object’ doesn’t exist as a constructor.