You are on page 1of 4

Module 5 JavaScript Objects

By: Merlie Ofiaza Department of Information Technology Studies 1


JavaScript Objects
An object is a collection of properties, and a property is an association between a name (or
key) and a value.

Creating Objects in JavaScript


There are 3 ways to create objects.
1. By object literal
2. By creating instance of Object directly (using new keyword)
3. By using an object constructor (using new keyword)

1. JavaScript Object by object literal


o The syntax of creating object using object literal is given below:

object​={property1:value1,property2:value2.....propertyN:valueN}

o property and value is separated by : (colon).

2. By creating instance of Object 


o The syntax of creating object directly is given below:

let ​objectname​=​new​ Object();

 
3. By using an Object constructor 
o The JavaScript ​this​ keyword refers to the object it belongs to or​ it refers to the current object

By: Merlie Ofiaza Department of Information Technology Studies 2


Accessing Object Properties
● objectName.propertyName
Example: shoes.style;

● objectName[​"propertyName"​]
Example: shoes[“style”];

​For more readings​:


JavaScript Objects. ​https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects

By: Merlie Ofiaza Department of Information Technology Studies 3


By: Merlie Ofiaza Department of Information Technology Studies 4

You might also like