Getter and setter properties in JavaScript
Вставка
- Опубліковано 5 вер 2024
- In this lecture, you will learn, what is getter and setter properties are and how to use them in your JavaScript program. Getter and setter properties were introduced with the release of ECMAScript 5.
One of the most well explained videos that I have seen and I have seen a lot of videos. Really appreciate it. It is a shame that this channel's videos have gotten so much less views.
Danke!
Best tutorial about getter setter out of the several videos I watched. Thank you!
Watched the first few youtube recommendation for getter and setter which made me more chaotic ..THIS WAS CRYSTAL CLEAR .THANKS BROTHER . KEEP GOING
Best lecture, After searching lot of lectures , I find this. Thank you 🙏
You made it super easy to understand. Thanks for the video. God bless you
That's literaly the best video i've seem about getters and setters on javascript. Thanks man!
you made it so easy to understand. Thank you for your hard work , sir.
this channel is a gold
PLEASE RELEASE TUTORIAL ON BACKEND LAMGUAGES LIKE JAVA/PYTHON/C++/PHP
Thank you ❤
Sir, I cannot have either get or set property alone. Although I only write get method for company , I can still set as User.company = 'abc' and company changed.
All properties in this tutorial are public, so we always have access to them. How to make properties in JavaScript private?
JavaScript isn't a language like c, java or c++. The variables in JavaScript are determined private and public by the let and val keyword. let for private and val for public.
Hi,
I am new to programming, but as far as I know, in langauges like C#, you can make a property private, i.e., truly encapsulate it, hence making the use of getters and setter a NECESSITY, but here why would I NEED to use getters and setters when I can easily access and modify the properties? You said there are two reasons:
1) Encapsulation
2) When you modify/calculate a value.
The second one makes sense, but you didn't give an example for the first one: how can you hide your data from the world when you can't make it private? Or maybe you can?
Thanks,
To hide the properties of the class or to make the properties of class private we use _ sign with properties.
For example: constructor(name,password){
this._name=name;
this._password=password;
}
Now name and password properties are private and we can use get and set methods to perform operations on it indirectly