var key = 'a'; map[key] = 'value';
map['a'] = 'value';
In Java this is optimized automatically during compilation. I want to know if any JS compiler does such optimization on its own.
var key = 'a';
map[key] = 'value';
map['a'] = 'value';
In Java this is optimized automatically during compilation. I want to know if any JS compiler does such optimization on its own.
This answer is relevant here; there's no difference in performance as one is an alias of the other. You can see that these have the same performance by testing it:
var objectTest = {
a: 1,
}
console.time('dot');
for (var i = 0; i < 100000000; i++) {
objectTest.a = objectTest.a + 1;
}
console.timeEnd('dot');
objectTest = {
a: 1,
}
console.time('bracket');
for (var i = 0; i < 100000000; i++) {
objectTest['a'] = objectTest['a'] + 1;
}
console.timeEnd('bracket');
Hence, there's no compiler, the chance of any optimization is very low.
var key = 'a';
map['a'] = 'value';
I think interpreter sees [a]
as a normal variable thus, it is kept in the heap. So, both of this access types are equal (costly speaking). On the other hand, using static statements are always should be avoided.