What is the difference between property1 and property2 in the following code?

// create object a
var a = {};

// Add property1 to a
a.property1 = 1;

// Add property2 to a
a['property2'] = 2;

// Add function 'function3' to a
a.function3 = function() {
  return this['property1'] + this.property2;
};

var html = 'a["property1"] + a.property2 = ' + a.function3();
document.getElementById('content').innerHTML = html;​

Please help !!!

Member Avatar for stbuchok

There isn't one. It is just 2 different ways of calling a property. Remember, this is JavaScript, not Java or C or C++ or C#. This is a different language all together, just similar syntactically.

This means that putting the property in quotes doesn't change it's meaning .... !!!!??
:O

Member Avatar for stbuchok

As far as I know, no. It's just 2 different way to reference a property of an object.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.