Started learning javascript
and currently going thru object topic.
<!DOCTYPE html>
<html>
<body>
<h3>object prop access</h3>
<p id="demo"></p>
<p id="test"></p>
<script>
var foo = {unique_prop: 1}, bar = {unique_prop: 2}, object = {};
object[foo] = 'value1';
//console.log(object[bar]);
document.getElementById("demo").innerHTML = "Object property:"+object[bar];
document.getElementById("test").innerHTML = "Object property object[foo]:"+object[foo];
</script>
</body>
</html>
When I run this program it prints value "value1
" , "value1
" in separate lines.
My question is there is no property name "bar
" defined for "object
" then why object[bar]
prints value "value1
" - which is assigned to object[foo]
.
--Divyesh