Question from the Javascript test

Which of the following code will log the message 'baz'?

Hard

Either the following code:

function Player(name) {
    this.name = name;

    this.identity = function() {
        console.log('foo');
    }
}

Player.identity = function identity() {
    console.log('bar');
}

Player.prototype.identity = function identity() {
    console.log('baz');
}

let myObj = Player('qux'); // Create a player
myObj.identity();

What will be the logged message?

Author: Jean-marie CléryStatus: PublishedQuestion passed 2035 times
Edit
2
Community Evaluations
developer avatar
Obsolete
Benoit
17/09/2024
plus personne ne code comme ça depuis 10 ans