0

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 !!!

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by stbuchok
0

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.

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.