+ 4

about getters and setters

What exactly do the getters and setters do in JavaScript? Can someone please answer me in brief .

14th Jul 2018, 12:48 PM
Shivam Mirje
Shivam Mirje - avatar
5 ответов
+ 7
Hello, Shivam Mirje ! "Getter" - allows you to get values ​​(read values). "Setter" - write values ​​to a variable. In the code they are the usual methods. But the method name always starts with the prefix get or set.
14th Jul 2018, 12:58 PM
Alexander Sokolov
Alexander Sokolov - avatar
14th Jul 2018, 1:54 PM
ODLNT
ODLNT - avatar
+ 2
Getters allow you to get the value, but you can add other code to it. Setters allow you to set the value, and you can add other code to it. Hope it helps!😉
14th Jul 2018, 11:17 PM
Rowsej
Rowsej - avatar
+ 1
Thank you all for your answers. They helped me a lot. :)
14th Jul 2018, 4:59 PM
Shivam Mirje
Shivam Mirje - avatar