FrontendChallenges is a collection of frontend interview questions and answers. It is designed to help you prepare for frontend interviews. It's free and open source.
difficulty: easy
title: Two functions - one object
type: question
template: javascript
tags: javascript, objects
Question
Is it possible to create two constructor functions, A and B, such that new A() is equal to new B() when compared using the == operator?
Given the following setup:
function A() { ... }
function B() { ... }
let a = new A();
let b = new B();
alert(a == b); // true
Provide the implementations for A and B that satisfy the condition a == b.
Template
index.js
export function A() {
// your code here
}
export function B() {
// your code here
}
index.test.js
import { A, B } from './';
describe('Constructor Functions A and B', () => {
test('new A() should equal new B()', () => {
let a = new A();
let b = new B();
expect(a).toBe(b);
});
});
Info
Question
Is it possible to create two constructor functions, A and B, such that new A() is equal to new B() when compared using the == operator?
Given the following setup:
Provide the implementations for A and B that satisfy the condition a == b.
Template
index.js
index.test.js