JavaScript Objects


JavaScript Object
JavaScript is designed on a simple object-based paradigm. An object is a collection of properties, and a property is an association between a name (or key) and a value. A property's value can be a function, in which case the property is known as a method. In addition to objects that are predefined in the browser, you can define your own objects. This chapter describes how to use objects, properties, functions, and methods, and how to create your own objects.

Object
"Everything" in JavaScript acts like an object such as a String, a Number, an Array, a Function..., with two exceptions, null and undefined.

Creating JavaScript Objects

In JavaScript, there are many ways to create objects. You can create an object using an object initializer or write a constructor function to define the object type and create an instance of the object with the new operator. JavaScript's "Object initializer" is consistent with the terminology used by C++.

Syntax
Using an object literal - {} notation you can create a plain object :
var objectName = {}
or
You can create new object like this -
var objectName = { property1 : value1,
                   property2 : value2,
                   //...,
                   propertyN : valueN };

Example :-
var myCar = new Object();
myCar.make = 'Aulto';
myCar.model = 'i10';
myCar.year = 2017;