Checks if both values have the same constructor.
Compares the constructor property of two values to determine if they are instances of the same class or type.
first value to compare
second value to compare
true if both values have the same constructor
hasSameConstructor([], [1, 2, 3]) // true (both Arrays)hasSameConstructor({}, { a: 1 }) // true (both Objects)hasSameConstructor([], {}) // false (Array vs Object)hasSameConstructor(new Date(), new Date()) // true (both Dates)hasSameConstructor('string', 42) // false (String vs Number) Copy
hasSameConstructor([], [1, 2, 3]) // true (both Arrays)hasSameConstructor({}, { a: 1 }) // true (both Objects)hasSameConstructor([], {}) // false (Array vs Object)hasSameConstructor(new Date(), new Date()) // true (both Dates)hasSameConstructor('string', 42) // false (String vs Number)
Checks if both values have the same constructor.
Compares the constructor property of two values to determine if they are instances of the same class or type.