One way to create an object (preferable!!) - Node.js Object

Node.js examples for Object:Object Operation

Description

One way to create an object (preferable!!)

Demo Code


var person1 = {//  w  w w  .  ja v  a 2  s  .co m
    name: 'Isak',
    age: 34
};

var person2 = {
    name: 'Isak',
    age: 34
};

// Another way of creating an object 
var anotherPerson = new Object();
anotherPerson.name = 'Pelle';
anotherPerson.age = 30;
console.log(anotherPerson);

var anotherPerson2 = new Object();
anotherPerson2.name = 'Isak';
anotherPerson2.age = 34;
console.log(anotherPerson2 === person1); // false, objects are reference types so cant be compared!
console.log(person2 === person1); // false, objects are reference types so cant be compared!

Related Tutorials