This Keyword

Dear Sciaku Learner you are not logged in or not enrolled in this course.

Please Click on login or enroll now button.

If you have any query feel free to chat us!

Happy Coding! Happy Learning!

Lecture 195:- This Keyword

The this keyword is a special keyword in JavaScript which refers to the object that is currently executing the code. The value of this is determined by the context in which it is used.

In a global context, this refers to the global object, which is window in a browser environment and global in a Node.js environment.

In the context of a function, the value of this depends on how the function is called. If a function is called as a method of an object, this refers to the object on which the method is called. If a function is called as a standalone function, this refers to the global object.

Arrow functions, on the other hand, inherit the this value from the surrounding context. This means that if an arrow function is used inside a method of an object, the this value inside the arrow function will still refer to the object.

Here is an example to illustrate the use of this keyword:

javascriptCopy code

let person = {  firstName: "John",  lastName: "Doe",  fullName: function() {    console.log(this.firstName + " " + this.lastName);  } }; person.fullName(); // Outputs "John Doe"

In this example, this refers to the person object inside the fullName method. When we call person.fullName(), it will output "John Doe" because this.firstName refers to "John" and this.lastName refers to "Doe".

22. Constructors And Prototypes

2 Comments

@niteshguptav63
niteshguptav63 Nov 17, 2024 at 1:39 PM

I am not able to access videos from second class and further. I have already completed first class

@niteshguptav63
niteshguptav63 Nov 16, 2024 at 10:56 AM

When will I get my course?

@admin79
admin79 Nov 17, 2024 at 1:29 PM

Now, Your query was resolved.

Frequently Asked Questions About Sciaku Courses & Services

Quick answers to common questions about our courses, quizzes, and learning platform

Didn't find what you're looking for?

help_center Contact Support