The following points summarize what you should have learned by reading this book (and investigating the code examples). Read each summary, and if you don't understand what is being said, return to the topic in the book.
- An object is made up of named properties that store values.
- Objects are created by invoking a constructor function with the
newkeyword, or by using a shorthand literal expression.
- Constructor functions are objects (
Boolean()constructors are dual-purposed in providing a) primitive values and b) object wrappers when needed, so that primitive values can act like objects.
- The values
falseare all primitive values, without an object nature unless treated like an object.
- When the
Error()constructor functions are invoked using the
newkeyword, an object is created that is known as a "complex object" or "reference object."
- Primitive values are stored by value, and when copied, are literally copied. Complex object values on the other hand are stored by reference, and when copied, are copied by reference.
- Primitive values are equal to other primitive values when their values are equal, whereas complex objects are equal only when they reference the same value. That is: a complex value is equal to another complex value when both refer to the same object.
- Getting/setting/updating an objects properties is done by using dot notation or bracket notation. Bracket notation is convenient when the name of the object property being manipulated is in the form of an expression (e.g.,
- When referencing object properties, a lookup chain is used to first look at the object that was referenced for the property. If the property is not there, the property is looked for on the constructor functions
prototypeproperty. If its not found there, because the prototype holds an object value and the value is created from the
Object()constructor, the property is looked for on the
Object.prototype). If the property is not found there, then the property is determined to be
- Because of the object property lookup chain (aka prototypal inheritance), all objects inherit from
Object()simply because the
prototypeproperty is, itself, an
thiskeyword, when used inside a function, is a generic way to reference the object containing the function.
- The value of
thisis determined during run time based on the context in which the function is called.
- Used in the global scope, the this keyword refers to the global object.
- Functions (specifically, encapsulated functions) create a scope chain for resolving variable lookups.
- The scope chain is set up based on the way code is written, not necessarily by the context in which a function is invoked. This permits a function to have access to the scope in which it was originally written, even if the function is called from a different context. This result is known as a closure.
- Function expressions and variables declared inside a function without using
varbecome global properties. However, function statements inside of a function scope remain defined in the scope in which they are written.
- Functions and variables declared (without
var) in the global scope become properties of the global object.
- Functions and variables declared (with
var) in the global scope become global variables.
Thank you for reading!
Weekly email summarySubscribe below and we’ll send you a weekly email summary of all new Code tutorials. Never miss out on learning about the next big thing.