Accessing Js object properties :
What is the difference between :
1) Obj.src
vs
2) Obj["src"]
I only know that #1 can't be used with number ( e.g. if the property name is "1")
Is there any other major differences ?
No difference really. Old'ish browser showed some performance differences using either the one or the other notation, but those times are over.
The only important difference is that the bracket notation is your only chance to dynamically access Object properties.
For instance:
var access = 'src';
Obj[ access ];
you can't do that using a dot notation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With