Objects and its Representation
Object are the important
data type and forms the building blocks for the JavaScript. These are different
from JavaScript's primitive data types like Number,String,Boolean,null,
undefined and symbol.
Objects are more complex
and it may contain combination of these primitive data types as well as
reference data types.Object is a reference data types and variables that are
assigned as reference value or pointers to that value. Object is collection of
related data in the form of key values called variables and methods(simply
state and behaviour).
Example : Object is
student and it'll have properties like names, age, address, standard.
And its representation are like :
Let's create an object
named Car and properties named company, model, year.
var car = new Object();
car.company = 'Buccati';
car.model = 'Chevron'
car.year = 2015;
Unassigned properties of object are undefined and not null.
car.color; //undefined
Properties of javascript
can be accessed using bracket notation.
car['company'] =
'Buccati';
car['model'] = 'Chevron';
car.year = 2015;
Creating Objects in
JavaScript:
·
With Object Literal
let car = {name:
'Buccati', year:2015};
·
With Keyword new
var student = new
Object();
student.name = 'Viki';
·
With method and constructor