Skip to main content

Posts

Showing posts with the label object in javascript

Object in JavaScript - Object Creation by Constructor, Function and Prototype

How to create a JavaScript object? The JavaScript object  is a collection of properties and the each property associated with the name-value pairs . The object can contain any data types (numbers, arrays, object etc.) The example looks like, Var myObject= {empId : “001”, empCode :”X0091”}; In the above example, here are two properties one is empId and other is empCode and its values are “001” and “X0091”. The properties name can be string or number. If a property name is number i.e. Var numObject= {1 : “001”, 2 :”X0091”}; Console.log(numObject.1);   //This line throw an error! Console.log(numObject[“1”]);   // will access to this line not get any error! As per my thought, the number property name should be avoided. Types of creating an object ( There are two types ) 1.       Object literals 2.       Object constructor Object Literals : This is the most common way to ...