Review

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.
  • Most everything in JavaScript can act like an object. Complex values are objects, and primitive values can be treated like objects. This is why you may hear people say that everything in JavaScript is an object.
  • Objects are created by invoking a constructor function with the new keyword, or by using a shorthand literal expression.
  • Constructor functions are objects (Function() objects), thus, in JavaScript, objects create objects.
  • JavaScript offers nine native constructor functions: Object(), Array(), String(), Number(), Boolean(), Function(), Date(), RegExp(), and Error(). The String(), Number(), and 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 null, undefined, "string", 10, true, and false are all primitive values, without an object nature unless treated like an object.
  • When the Object(), Array(), String(), Number(), Boolean(), Function(), Date(), RegExp(), and Error() constructor functions are invoked using the new keyword, an object is created that is known as a "complex object" or "reference object."
  • "string", 10, true, and false, in their primitive forms, have no object qualities until they are used as objects; then JavaScript, behind the scenes, creates temporary wrapper objects so that such values can act like objects.
  • 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.
  • Due to the nature of complex objects and references, JavaScript objects have dynamic properties.
  • JavaScript is mutable, which means that native objects and user-defined object properties can be manipulated at any time.
  • 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., Array['prototype']['join'].apply()).
  • 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 prototype property. 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() constructors prototype property (Object.prototype). If the property is not found there, then the property is determined to be undefined.
  • The prototype lookup chain is how inheritance (aka prototypal inheritance) was design to be accomplished in JavaScript.
  • Because of the object property lookup chain (aka prototypal inheritance), all objects inherit from Object() simply because the prototype property is, itself, an Object() object.
  • JavaScript functions are first-class citizens: functions are objects with properties and values.
  • The this keyword, when used inside a function, is a generic way to reference the object containing the function.
  • The value of this is 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.
  • JavaScript uses functions as a way to create a unique scope.
  • JavaScript provides the global scope, and its in this scope that all JavaScript code exists.
  • 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 var become 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.

Conclusion

Thank you for reading!

Tags:

Comments

Related Articles