Given the following object:
const myObject = {
color0: '#000000',
color1: '#FFFFFF',
color2: '#AAAAAA',
color3: '#000000'
}
Would myObject
consume less memory to declare it like this?
const myObject = (() => {
const color000000 = '#000000'
return {
color0: color000000,
color1: '#FFFFFF',
color2: '#AAAAAA',
color3: color000000
}
})()
The difference between the two is that since '#000000'
is repeated multiple times, theoretically it would be more efficient to have them pointing to the same memory address.