Summary

In Chapter 2, Primitive Data Types, Arrays, Loops, and Conditions, you saw that there are five primitive data types (number, string, Boolean, null, and undefined), and we also said that everything that is not a primitive piece of data is an object. Now, you also know that:

  • Objects are like arrays, but you specify the keys
  • Objects contain properties
  • Properties can be functions (functions are data; remember var f = function () {};). Properties that are functions are also called methods
  • Arrays are actually objects with predefined numeric properties and an auto-incrementing length property
  • Array objects have a number of convenient methods (such as sort() or slice())
  • Functions are also objects, and they have properties (such as length and prototype) and methods (such as call() and apply())

Regarding the five primitive data types, apart from undefined and null, the other three have the corresponding constructor functions-Number(), String(), and Boolean(). Using these, you can create objects, called wrapper objects, which contain methods for working with primitive data elements.

Number(), String(), and Boolean() can be invoked:

  • With the new operator, to create new objects.
  • Without the new operator, to convert any value to the corresponding primitive data type.

Other built-in constructor functions you're now familiar with include Object(), Array(), Function(), Date(), RegExp(), and Error(). You're also familiar with Math-a global object that is not a constructor.

Now, you can see how objects have a central role in JavaScript programming, as pretty much everything is an object or can be wrapped by an object.

Finally, let's wrap up the literal notations you're now familiar with:

Name

Literal

Constructor

Example

Object

{}

new Object()

{prop: 1}

Array

[]

new Array()

[1,2,3,'test']

Regular expression

/pattern/modifiers

new RegExp('pattern', 'modifiers')

/java.*/img

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.197.123