Reputation: 2170
When using an Object as a set in ES5 eg:
var thingsSeen = {};
thingsSeen["cat"] = true;
thingsSeen["dog"] = true;
Does it make any difference to use a number as the value instead of a boolean? Which is better in practice and why?
Upvotes: 0
Views: 25
Reputation: 288520
You can store a boolean in a single bit. You need 64 bits for a number.
Then different implementations may use additional memory, e.g. a whole byte for the boolean. But most probably the number will need more memory.
Upvotes: 1