This Keyword & Execution Context Interview Questions

    Question 1: Global this in Browser

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

    Question 2: Global this in Strict Mode

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

    Question 3: this in Object Method

    What does the following code output?

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

    Question 4: this in Arrow Functions

    What is special about this in arrow functions?

    Question 5: Function this in Non-Strict Mode

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

    Question 6: this with call()

    What does the following print?

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

    Question 7: this in setTimeout

    What does the following code output in a browser?

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

    Question 8: Execution Context

    How many phases does the JavaScript execution context have?

    Question 9: Types of Execution Context

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

    Question 10: this 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();