Console Learner — An interactive JavaScript course.


2.2 Property Access (Objects)

>>>
var o = { key: 'value' }


  
>>>
o.key
"value"
The . dot operator is used to access a property in an object.
>>>
o['key']
"value"
The array index syntax can also be used to access a property in an object. This syntax must be used when the property name contains spaces or non alphanumeric characters.
>>>
var propName = 'key'


  
>>>
o[propName]
"value"
The index syntax is also used when the property name is dynamic or stored in a variable
>>>
o.text = 1
1
New properties are added with assignment, using either of the two access syntaxes above.
>>>
o.doesNotExist
undefined
It is not an error to access a property that doesn't exist.
>>>
delete o.text
true
The delete operator removes properties (or global variables).
>>>

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.