Reflect.apply() — JS Technical Interview Questions & Answers

Calls a function with a given this and argument array.

Reflect.apply()

  • Reflect.apply() is a JS topic. In plain words you use it for a short Reflect.apply example in a script in the browser. Don’t start with a slogan — start with that picture.
  • Smallest example: the smallest Reflect.apply example you can type. Type it, run it, and say what you see. If you can do that from memory, you know Reflect.apply().
  • From the example next to this theory: Calls a function with a given this and argument array.
  • Trap: only saying “Reflect.apply” with no example. Fix that before you talk about advanced JS.
  • Viva: what is Reflect.apply()? Then show the smallest Reflect.apply example you can type. Then name the trap.

Technical Interview Tip: What is Reflect.apply()? Show this: the smallest Reflect.apply example you can type. Trap: only saying “Reflect.apply” with no example.

Code Examples for Reflect.apply()

Reflect.apply() — working example

const user = {
  name: "Ada",
  greet() {
    return "Hi " + this.name;
  },
};

console.log(user.greet());

function greet() {
  return "Hi " + this.name;
}
console.log(greet.call({ name: "Lin" }));
console.log(greet.apply({ name: "Riya" }));
const bound = greet.bind({ name: "Sam" });
console.log(bound());

Reflect.apply() — this depends on how a function is called; call/apply/bind set it explicitly.

How to Explain Reflect.apply() to an Interviewer

What is Reflect.apply()?

Used for a short Reflect.apply example a script in the browser Not just the heading

Give one small example of Reflect.apply().

the smallest Reflect.apply example you can type Calls a function with a given this and argument array

What mistake do beginners make with Reflect.apply()?

only saying “Reflect.apply” with no example Show the fix

Where do you use Reflect.apply()?

a script in the browser a short Reflect.apply example