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:
var f = function () {};
). Properties that are functions are also called methodslength
propertysort()
or slice()
)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:
new
operator, to create new objects.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 |
|
|
|
Array |
|
|
|
Regular expression |
|
|
|