2 ms·
In JavaScript it's only the primitive objects (Number, String, Boolean, null, undefined) that are "by value". Everything else is "by reference". And when you wr
by z3t4 9y ago
In JavaScript it's only the primitive objects (Number, String, Boolean, null, undefined) that are "by value". Everything else is "by reference". And when you write {foo:1} you create a new object. So it's logical that array.includes({foo:1}) is false. You can however point {foo:1} to a variable, and then use that variable as a reference, eg. var foo = {foo: 1}; array.push(foo); array.includes(foo);