In this snippet of code I'm defining two functions, outputting them and their string representations to console, and also comparing them:
var a = function func() {},
b = function func() {};
// string representations are equal
console.log(a.toString());
console.log(b.toString());
console.log(a.toString() == b.toString());
console.log(a.toString() === b.toString());
// functions seem to be equal
console.log(a);
console.log(b);
// but they're not really as this prints false
console.log(a == b);
console.log(a === b);
Why are they not equal?
Same happens of course to empty plain objects, i.e. {}
.
Funny thing though is that lodash isEqual
returns true
in this case: _.isEqual({}, {});
and false
in this: _.isEqual(function () {}, function () {})
. But of course it's not any proof, it's just the way of implementation of equality.