Signup/Sign In

'this' Keyword in JavaScript Test

JavaScript Avg. Score: 2.34 160 Beginner
Q.1 What is the syntax to access 'this' in JavaScript?
Q.2 What will be the output of the following code:
function func() {
    return this;
}
const obj1 = { name: "obj1" };
obj1.func = func;

const obj3 = {
  __proto__: obj1,
  name: "obj3",
};

console.log(obj3.func());

 

Q.3 What will be the output of the following code:
function getMeThis() {
    return this;
}

console.log(typeof getMeThis());

 

Q.4 What will be the output of the following code:
function getMeThis() {
    "use strict";
    return this;
}

const obj1 = { name: "obj1" };
obj1.getMeThis = getMeThis;

console.log(getMeThis());

 

Q.5 What will be the output of the following code:
'use strict';

const foo = () => this;
console.log(foo());

 


Studytonight logo

Find me on YouTube

I make videos for Fullstack Dev, AWS, Ethical Hacking and Foundational stuff.