Extremly eye opening concept of THIS .... well taught .... why your channel is underratted ? LOVE THE CONCEPT YOU TAUGHT ... NO BODY ELSE DO THAT NOT EVEN JONAS the udemy instructor
Just a suggestion you can also explain the call apply bind with the same example . Where before changing it to arrow function of greet2 (with the same normal function greet 2 we can apply call,apply and bind to get the same output like "greet2.apply(this);" (or) greet2.call(this); (or) greet2.bind(this)(); ) which also covers the call, apply and bind methods
Sir, Greet1 function is also defined in the person object scope, but if we use arrow function on greet1 then , this refers to window object instead it should point to person object
Will check and answer soon. Bit busy now a days. Please don't paste other channels urls or links. Hope you understand. Instead you can provide your understanding.
Sorry for late reply, as I mentioned in the video arrow function will not have own this. You can explicitly pass the scope using bind. Will try to cover everything about arrow functions and scope in next video. Thanks for understanding and interest.
The reason is object doesn't have any 'this'. In FAF, greet1 is referring to the window. Whereas in the greet2 (FAF) this is getting inherited from the parent and in this case it is a normal function and normal function has this. Hence, greet2 (FAF) is able to return the output.
Could you please explain. You said in arrow function it matters where function is defined. And greet2 is defined in the person object. This is the explanation you gave. Lets convert greet1 function to arrow function. Then the greet1 arrow function will also defined in the person object right. Then this will not reference the person object. But it still defined in the person object. Need some explanation please.. Thanks in advance ...
Sorry for late reply, as I mentioned in the video arrow function will not have own this. You can explicitly pass the scope using bind. Will try to cover everything about arrow functions and scope in next video. Thanks for understanding and interest.
Hi @CodeWellTech, Great Vedio, with clear explianation but I have a doubt in the below snippet and your statement. Could you please help. Thanks const obj = { name:'shree', age: 23, greet: ()=>{ console.log(`Hello, my name is ${this.name } and I am ${this.age} years old.`); } }; obj.greet(); this in ()=>: Based on the scope of arrow function defined within.
Hey, thanks for video. Great explanation but I have a doubt. const person = { name: "max", age:19, greet : () => { console.log(this.name); } }; Why it throws undefined?
Thanks for the video, but it doesn't explain why in the greet2 function, "this" refers to the Window object. Also it sounds like you're recording the video in a large cave
What's wrong with this code? It display "cannot read properties of undefined in the following code.. var age = 28; function displayAge() { console.log(this.age); console.log(this); } displayAge(); var person = { age: 26, displayAge: displayAge, }; person.displayAge(); If you use non strict mode, can you please use strict mode since this way is much more acceptable these days. By the way, your method of teaching is really understandable. I feel very sorry why it doesn't work for me! Also, woould you please use a better mic so that we can hear better. There's some noise behind..🙏🙏🙏
let name = "xxx"; const obj1 = { name: "myName", getName: ()=> { console.log(this.name); } } obj1.getName(); // undefined why output is like this in VSCODE?
Since you have defined getName as arrow function and calling getName globally it is undefined. In this case this points to window object. Define getName as normal function then you see output as you expected
Hey Guys, if this video is helpful to you , then please Hit the LIKE and SUBSCRIBE button that means a lot 🙏
so many channels with million of subscribers could not justify this explanation!, Thank you so much
Clear explanation ..Thanks
Clear Explanation about the flow of this keywords in Normal and Arrow function .... Thanks for the clarification.
Nice explanation!...gone through many videos for this keyword, but your video was the only which clearly taught about THIS keyword in javascript.
Thanks 👍
Crystal clear, I was so confusing before this video about this keyword.
Now I am so confident 🙏🙏🙏🙏🙏
wow how you demonstrate is amazing
Thanks 🙏
best video on "this" topic ,thanks
Thanks 🙏
This video and this channel is a hidden gem
One of the best explanations of this concept ! Thank you !
Excellent and Clear explanation!!
ah this is the best video i’ve seen on this topic, really cleared some things up for me. thank you!
Nicely explained thanks
Kindly subscribe
Thanks......seen multiple videos to clear that key difference....finally cleared for lifetime.
Thanks for compliment 😊
Thanku so so so so so much 😍😍😍😍😍😍
Great lesson! Thank you very much!
why your channel is so underrated? loved your way of teaching thanks for “this” tutorial😜
best explanation of this keyword so far.. thanks a lot
Thanks a lot kindly share with others
Very good explanation
Tq ... will be appreciated if you share with others 😎
very good explanation, thanks
Perfect explanation
Thank you 😊
loved the explanation. Lot's of love from Kolkata!
Deserves so many more views, super good explanation of an unintuitive topic
Glad you liked it. Kindly share it.
great & easy
Thanks for breaking this down so clearly!
Great explanation 👍🏼👍🏼👍🏼, deserve more views nad likes 👍🏼👍🏼
Thanks a lot. Kindly share it.
Awesome!!!!!
Thanks
best explnation till date...about scope of this in arrow and normal function...Thanks a lot!
Thanks for feedback 😊
Subscribed Man !!!!
Awesome, simple and clear explanation.
Thanks.
Extremly eye opening concept of THIS .... well taught .... why your channel is underratted ?
LOVE THE CONCEPT YOU TAUGHT ... NO BODY ELSE DO THAT NOT EVEN JONAS the udemy instructor
Thank you so much for explaining this way
Most straightforward explanation ever, Thank you!!🙏
Glad you like it 😊
Very well explained. It was so easy to understand all the points. Thank you 🙏.
Glad you liked it.
Just a suggestion you can also explain the call apply bind with the same example . Where before changing it to arrow function of greet2 (with the same normal function greet 2 we can apply call,apply and bind to get the same output like "greet2.apply(this);" (or) greet2.call(this); (or) greet2.bind(this)(); ) which also covers the call, apply and bind methods
Sure bro 😊
Worth to watch your video
Thanks for kind feedback 😊
Good video.. the way you explain is very nice.. this video deserves more likes and views
Thanks a lot
Many, many thanks Sir!
Thanks a lot for feedback.
Great job bro!
Thanks 😊
thank you! easy to understand
damn you earned a subscriber here . Thanks❤
VERY VERY NICE EXPLAINATION
Thank you brother
Your amazing explanation made it so easy to understand the whole topic. Thanks a lot!
Really thanks for feedback. Sharing of this video will appreciated 😊
Thanks bro.....
Amazing 😊😊
Sir, Greet1 function is also defined in the person object scope, but if we use arrow function on greet1 then , this refers to window object instead it should point to person object
Will check and answer soon. Bit busy now a days. Please don't paste other channels urls or links. Hope you understand. Instead you can provide your understanding.
Sorry for late reply, as I mentioned in the video arrow function will not have own this. You can explicitly pass the scope using bind. Will try to cover everything about arrow functions and scope in next video. Thanks for understanding and interest.
The reason is object doesn't have any 'this'. In FAF, greet1 is referring to the window. Whereas in the greet2 (FAF) this is getting inherited from the parent and in this case it is a normal function and normal function has this. Hence, greet2 (FAF) is able to return the output.
❤❤
Thank you sir
Great video and thanks but what is going on when you use setInterval, why it always set it back to window object? How setInterval calls its function?
Thank you so much, you made it so easy to understand 🔥🔥 💯
please do more videos on the front end .very good content
Thanks Anand. Kindly like and follow my videos. Will do more videos on frontend.
Thanks sir love you from Pakistan ❣️❣️
Could you please explain. You said in arrow function it matters where function is defined. And greet2 is defined in the person object. This is the explanation you gave. Lets convert greet1 function to arrow function. Then the greet1 arrow function will also defined in the person object right. Then this will not reference the person object. But it still defined in the person object.
Need some explanation please.. Thanks in advance ...
i have the same ques
Sorry for late reply, as I mentioned in the video arrow function will not have own this. You can explicitly pass the scope using bind. Will try to cover everything about arrow functions and scope in next video. Thanks for understanding and interest.
Hi @CodeWellTech,
Great Vedio, with clear explianation but I have a doubt in the below snippet and your statement. Could you please help. Thanks
const obj = {
name:'shree',
age: 23,
greet: ()=>{
console.log(`Hello, my name is ${this.name } and I am ${this.age} years old.`);
}
};
obj.greet();
this in ()=>: Based on the scope of arrow function defined within.
Thank you so much 💞💞
Lucid Explanation
Thank you very much 😊
Your last example of the arrow function would've worked with a named function as well 🤔
Thanks for your thoughts
@@CodeWellTech Great walkthrough and thoroughly explained. Thank you so much!
Thank you so much!!!
Thank you ❤️
Hey, thanks for video. Great explanation but I have a doubt.
const person = {
name: "max",
age:19,
greet : () => {
console.log(this.name);
}
};
Why it throws undefined?
have you figured this out?
@@samking618 no
Thanks for the video, but it doesn't explain why in the greet2 function, "this" refers to the Window object. Also it sounds like you're recording the video in a large cave
Will make sure everything sounds clear next time. Thanks for feeding and understanding
thanks
why if I use global variable using var not let or const, the value of variable is null if I using this to refer to global object
The scope of let & const is different.
What's wrong with this code? It display "cannot read properties of undefined in the following code..
var age = 28;
function displayAge() {
console.log(this.age);
console.log(this);
}
displayAge();
var person = {
age: 26,
displayAge: displayAge,
};
person.displayAge();
If you use non strict mode, can you please use strict mode since this way is much more acceptable these days. By the way, your method of teaching is really understandable. I feel very sorry why it doesn't work for me! Also, woould you please use a better mic so that we can hear better. There's some noise behind..🙏🙏🙏
let name = "xxx";
const obj1 = {
name: "myName",
getName: ()=> {
console.log(this.name);
}
}
obj1.getName(); // undefined why output is like this in VSCODE?
Since you have defined getName as arrow function and calling getName globally it is undefined. In this case this points to window object. Define getName as normal function then you see output as you expected
If you still want arrow function then use obj1 instead of this when accessing obj1 properties