Quiz di JavaScript: this, call, apply & bind

This JavaScript quiz covers this, one of the most asked interview topics. You will work out what this is in methods, detached functions and arrow functions, and set it yourself with call, apply and bind.

Difficile 10 domande ~8 minuti Superato con il 80% Node.js 22

Scegli una modalità

Stai giocando come ospite: accedi per salvare XP e serie.

Domanda di esempio

Domanda 1 di 10

What does this print?

const user = {
  name: "Ann",
  greet() {
    return `Hi, ${this.name}`;
  },
};
console.log(user.greet());
Mostra la risposta

A. Hi, Ann When a function is called as user.greet(), this is the object before the dot. So this.name is "Ann".

Cosa copre questo quiz

  • this is decided by how a function is called, not where it is written
  • Losing this when a method is passed around
  • Arrow functions take this from the surrounding code
  • call and apply run a function with a chosen this
  • bind returns a new function with this fixed for good

Domande frequenti

Serve un account?

No. Chiunque può giocare. Accedi per salvare XP, serie, badge e cronologia.

Posso rifarlo?

Sì. Il tuo miglior punteggio resta salvato, e domande e risposte vengono mescolate ogni volta.