Section 6 - Building Objects
typeof, instanceof, and Figuring out what Type it is
typeof specifies what we might expect: it return the type of a variable.
Arrays are also object types - but we cant further specify what type of object.
Instance of looks down the prototype chain to see if an object is can be found inside of another object.
As a review, new returns a newly constructed object whose 'this' return the object it was constructed under.
Important note: instanceof does not compare two objects. Rather, it looks at where the source came from. When we create any object, we also create an instance of an object, that comes from the constructor.
A few more
console.log(undefined); //undefined console.log(null); // object var a = function z() {}; console.log(a); // function
null returns an object. This is still considered to be a bug.
And a function returns a function object.
Strict Mode
Can help prevent error under some circumstances.
Your telling the js engine to use some extra, more strict rules when running your code.
include on the top of a file, or function.
Same rules of scope apply
A bit dangerous, because if it cannot find a variable, it looks up the scope chain.
More strict parser settings are applied.
Not all js engines agree on what 'strict' means. Not 100% reliable.
Varies by browser.
Last updated
Was this helpful?