asuming that a "const" is constant, I wouldn't have thought that this is possible:
const obj = {
key1: value1,
key2: value2
};
obj["key3"] = value3;
obj.key4 = value4;
Can somebody explain it to me?
asuming that a "const" is constant, I wouldn't have thought that this is possible:
const obj = {
key1: value1,
key2: value2
};
obj["key3"] = value3;
obj.key4 = value4;
Can somebody explain it to me?
In your case, you aren't actually changing obj
. You're just changing a property of obj
, so it isn't considered like you're trying to change a constant.
Only doing this is problematic:
const obj = {
key1: value1,
key2: value2
};
obj = 5