JavaScript Interview Questions - Question 20
Автор: ByteWarp Dev
Загружено: 2024-06-06
Просмотров: 35
Описание:
@ByteWarpDev Presents
JavaScript Interview Questions
Question - 20:
Consider the following code:
const person = {
name: "John",
greet: function () {
console.log(this.name);
}
}
const greetFn = person.greet.bind({ name: "Jane" });
greetFn();
What will be the output of this code, and why?
Options:
a) "John"
b) "Jane"
c) undefined
d) ReferenceError
Answer:
b) "Jane"
Explanation:
In this code, we define an object "person" with a "name" property and a "greet" method. We then use the "bind" method to create a new function "greetFn" that binds its "this" context to "{ name: "Jane" }". When "greetFn" is invoked, it logs the "name" property of its bound "this" context, which is "Jane".
#bindmethod #thiskeyword #coding #interview #questionsandanswers #javascriptinterviewquestions
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: