Imagine you want describe a car: it has certain functions like moving forward/backward, steering right and left. It also has certain attributes like color of the car. In programming, we create objects that have the same functions that we can use, and similar attributes that we can customize.
In this module, you will learn about both built-in and user defined objects that you can use and create.
JavaScript contains a number of built-in objects. Some of these include Array, Date and String objects.
Using Array object
var cars = ['Volvo','Volkswagen','Toyota'];
The above code creates an array named cars which contains 3 elements - Volvo, Volkswagen and Toyota.
Using Date object
var today = new Date();
document.write(today.getDate()+'-'+today.getMonth()+'-'+today.getFullYear());
The above code will output today's date in dd-mm-yyyy format.
The variable today is a Date object.
getDate(), getMonth() and getFullYear() are built in date functions associated with a Date object.
Using String object