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

Comments: 2

profile
@niteshguptav63
17-Nov-2024, 01:39 PM

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

profile
@niteshguptav63
16-Nov-2024, 10:56 AM

When will I get my course?

profile
@admin79
17-Nov-2024, 01:29 PM

Now, Your query was resolved.

Frequently Asked Questions (FAQs)

How do I register on Sciaku.com?
How can I enroll in a course on Sciaku.com?
Are there free courses available on Sciaku.com?
How do I purchase a paid course on Sciaku.com?
What payment methods are accepted on Sciaku.com?
How will I access the course content after purchasing a course?
How long do I have access to a purchased course on Sciaku.com?
How do I contact the admin for assistance or support?
Can I get a refund for a course I've purchased?
How does the admin grant access to a course after payment?