Today we will see the output based question
1. Closure
function outer() { var x = 10; function inner() { console.log(x); } x = 20; return inner; } var closureFunc = outer(); closureFunc(); // output ?
2. This
const obj = { count: 0, increment() { this.count++; }, }; const increment = obj.increment; increment(); console.log(obj.count); // output ?
3. Arrow Function and this
const obj = { name: 'Alice', age: 30, sayHello: function() { setTimeout(() => { console.log(`Hello, I'm ${this.name} and I'm ${this.age} years old.`); }, 1000); }, }; obj.sayHello(); // output ?
4. Fn Borrow
const obj = { count: 0, increment() { this.count++; }, }; const increment = obj.increment.bind(obj); increment(); console.log(obj.count);
Write the answer in the comments
Top comments (0)