This Keyword & Execution Context Interview Questions

    Question 1Global this in Browser

    What does this refer to in the global scope in a browser?

    Question 2Global this in Strict Mode

    What does this refer to in global scope under "use strict"?

    Question 3this in Object Method

    What does the following code output?

    let person = { name: "Alice", greet: function() { console.log(this.name); } }; person.greet();

    Question 4this in Arrow Functions

    What is special about this in arrow functions?

    Question 5Function this in Non-Strict Mode

    In non-strict mode, what does this refer to inside a standalone function?

    Question 6this with call()

    What does the following print?

    function greet() { console.log(this.language); } greet.call({ language: "JavaScript" });

    Question 7this in setTimeout

    What does the following code output in a browser?

    setTimeout(function() { console.log(this); }, 1000);

    Question 8Execution Context

    How many phases does the JavaScript execution context have?

    Question 9Types of Execution Context

    Which of the following are types of execution context in JavaScript?

    Question 10this Inside a Class

    What does the following code output?

    class Car { constructor(name) { this.name = name; } showName() { console.log(this.name); } } let c = new Car("Tesla"); c.showName();