call and bind


Sat Oct 24 2020 07:32:55 GMT+0000 (UTC)

Saved by @snigdhakhurana10

const person = { name: 'Lydia' };

function sayHi(age) {
  return `${} is ${age}`;

console.log(, 21));
console.log(sayHi.bind(person, 21));

//With both, we can pass the object to which we want the this keyword to refer to. However, .call is executed immediately!

//.bind returns a copy of the function, but with a bound context! It is not executed immediately.