Complete the code to log the current object using this keyword.
const obj = { name: 'Alice', show: function() { console.log([1]); } }; obj.show();this inside the method.window which refers to the global object, not the current object.The this keyword inside the method refers to the current object obj.
Complete the code to correctly bind this inside the function.
function greet() { console.log('Hello, ' + this.name); } const person = { name: 'Bob' }; const greetPerson = greet.[1](person); greetPerson();call or apply which invoke the function immediately.set.The bind method creates a new function with this set to the given object.
Fix the error by completing the code to access this inside the arrow function.
const obj = { name: 'Carol', greet: function() { const arrow = () => console.log(this.[1]); arrow(); } }; obj.greet();this as a property name.obj directly inside the arrow function.Arrow functions do not have their own this, so they use the this of the surrounding function, which is obj.
Fill both blanks to create a method that returns the object's name using this.
const user = { [1]: function() { return this.[2]; }, name: 'Dave' }; console.log(user.getName());username.The method getName returns the name property of the object using this.
Fill all three blanks to create an object with a method that uses this to return a greeting.
const person = { [1]: 'Eve', [2]: function() { return `Hello, my name is [3].`; } }; console.log(person.greet());this.greet inside the template string instead of this.name.The object has a name property and a greet method that returns a greeting using this.name.