const arr = [1,2,3,4]; const coordinate = [arr + 2, arr + 1];
here arr is written out twice, when the code is executed would it literally go and find same value twice or would it remember it?
Does it matter that arr in example above is used in the same expression? What if I would use arr in the beginning of the file and at the end of the file?
Would it make sense to put arr into a variable for performance?
But you can't really rely on it. With compilers you can run them and inspect the results to see if it was optimized. With runtime optimizations, you don't even have that option - even if its optimized on your machine, that's no guarantee for the next guy, or even the next run.
If you know that the lookup is expensive (which is unlikely in your simple example), you should cache it yourself. If it's not expensive, save the effort for something that is.