JavaScript · Middle · Question 3 of 75

What does this code print?

function f() { return this.x; }
const g = f.bind({ x: 1 }).bind({ x: 2 });
console.log(g());

Explanation

A bound function "remembers" its context forever; a second bind can't change it (though it can add arguments). Only new can override this of a bound function.

Further reading

Problem with a question

JavaScript · Middle · question 3

Test yourself

Take the JavaScript · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz