Why in JS a.test = 1 when "a" is a number doesn't throw an error

Viewed 35

I tested this today and I don't understand the behaviour. For me, that should be an error.

const a = 1;
a.test = 1;

console.log(a)
console.log(a.test)

Someone have the answer ?

1 Answers

you can define properties pretty much anything, but in this case you are assigning it to a number which doesn't actually hold properties.

Related