simple object is created as below var myFriend = new Object(); myFriend.firstname = "rythm"; myFriend.lastname = "algo"; other way to instantiate is var myFriend = { firstname: " rythm ", lastname: " algo " }; Also to add a method var myFriend = { firstname: " rythm ", lastname: " algo ", printdetails: function() { alert("Hi " + this. firstname); alert ("Hi " + this lastname ); } }; We can use the method as below myFriend. printdetails ();
for (var prop in myFriend) { console.log("Name: " + prop + " Value: " + myFriend [prop]); } delete myData.printdetails;
The Equality Operator vs. the Identity Operator var firstVal = 5; var secondVal = "5"; if (firstVal == secondVal) { This compares only values if (firstVal === secondVal) { this checks type also
2012-08-17 01:22
This blog is frozen. No new comments or edits allowed.
simple object is created as below
var myFriend = new Object();
myFriend.firstname = "rythm";
myFriend.lastname = "algo";
other way to instantiate is
var myFriend = {
firstname: " rythm ",
lastname: " algo "
};
Also to add a method
var myFriend = {
firstname: " rythm ",
lastname: " algo ",
printdetails: function() {
alert("Hi " + this. firstname);
alert ("Hi " + this lastname );
}
};
We can use the method as below
myFriend. printdetails ();
update:
myFriend. firstname = "ram";
myFriend ["firstname "] = "patrick";
delete:
delete myFriend. firstname;
delete myFriend["firstname "];
for (var prop in myFriend) {
console.log("Name: " + prop + " Value: " + myFriend [prop]);
}
delete myData.printdetails;
The Equality Operator vs. the Identity Operator
var firstVal = 5;
var secondVal = "5";
if (firstVal == secondVal) { This compares only values
if (firstVal === secondVal) { this checks type also