DEV Community

Dharan Ganesan
Dharan Ganesan

Posted on

Day 13: Guess it

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 ?
Enter fullscreen mode Exit fullscreen mode

2. This

const obj = {
  count: 0,
  increment() {
    this.count++;
  },
};

const increment = obj.increment;
increment();
console.log(obj.count); // output ?

Enter fullscreen mode Exit fullscreen mode

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 ?
Enter fullscreen mode Exit fullscreen mode

4. Fn Borrow

const obj = {
  count: 0,
  increment() {
    this.count++;
  },
};

const increment = obj.increment.bind(obj);
increment();
console.log(obj.count);
Enter fullscreen mode Exit fullscreen mode

Write the answer in the comments

SurveyJS custom survey software

Build Your Own Forms without Manual Coding

SurveyJS UI libraries let you build a JSON-based form management system that integrates with any backend, giving you full control over your data with no user limits. Includes support for custom question types, skip logic, an integrated CSS editor, PDF export, real-time analytics, and more.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more