Bardy
Bardy

Reputation: 2170

Efficiency of value type when using a JS Object as a set in ES5

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

Answers (1)

Oriol
Oriol

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

Related Questions