Console Learner — An interactive JavaScript course.
1.2 Object Types
The primitive object type is the basis for the built-in
object types, some of which are:
Object – Container for a sequence of
named values (properties).
Array – Container for a sequence of
ordered values.
Boolean, Number & String –
Wrapper classes for a corresponding primitive value.
Function – Contains executable code
for a function (or procedure).
RegExp – Contains a compiled regular
expression.
Date – Contains a timestamp (date &
time) value.
Objects are implemented as an (ordered) hash set (i.e. a hash table).
This means that property lookup is an O(1) (constant time) operation.
So any object can serve as a quick lookup table.
Arrays are objects with positive numeric integer property names (instead
of strings). The built-in length property is also updated
automatically.
These are seldom used to create wrapper objects, as those are normally
not needed. However, they are sometimes used for type conversions (which
will be explained soon).
>>>
{ a: 'value', b: 123, 'c': null }
{ "a": "value", "b": 123, "c": null }
This object literal syntax is also known as
JSON and is
commonly used for data transfer.
>>>
[1, 2, 'c']
[1, 2, "c"]
Array literals are also part of JSON.
>>>
( function() {} )
function () {}
Functions are explained in detail in a later chapter. For now it
is enough to note that functions are first-class
citizens, i.e. can be handled as any other value.
>>>
/.*/g
/.*/g
A regular expression literal is converted to a
RegExp object at run-time, not parse-time. This
means that some errors won't be detected until the code is
executed.
>>>
The console allows you to interact with the course material and
examples. Use the following keys:
<Enter> — Execute the code
<Shift + Enter> — Add
line break
<Arrow-Up> — Previous
command in history
<Arrow-Down> — Next command in history
A special logging function is also available:
print(value) — Prints a value to
the console.
print(value, true) — Prints a debug
version of a value.
Need more magic? Check out the other
developer tools
on this site.