Console Learner — An interactive JavaScript course.


4.8 Function & Array Objects

>>>
typeof (new Function())
"function"
Although the Boolean, Number and String constructors create wrapper objects of little practical value, the Function constructor does not.
>>>
(function (){}) instanceof Function
true
Instead, function objects and function values are the same thing. Which is to say, not really a primitive type after all.
>>>
new Array(1,2,3)
[1, 2, 3]
For Array instances, the constructor function is mostly equivalent to using the literal syntax (JSON).
>>>
new Array(3)
[undefined, undefined, undefined]
The only exception is when a single numeric argument is used. In this case, the result is an empty array of the specified length. Using the Array constructor is therefore discouraged, as the literal syntax is less error-prone and more compact.
>>>
new Object()
{}
Similar to Array, the Object constructor should also be avoided in most cases. Using the {} syntax is both clearer, more compact and more flexible.
>>>
Object(null)
{}
The Boolean, Number, String and Object constructor functions can also be called without new. This coerces the value into the corresponding (primitive) type. This isn't automatically true for other constructor functions, however.
>>>

The console allows you to interact with the course material and examples. Use the following keys:

A special logging function is also available:


Need more magic? Check out the other developer tools on this site.