Posts

Showing posts with the label Properties in JavaScript

Properties In Javascript By Sagar Jaybhay 2020

In this article we will understand Properties in Javascript . How to write properties in Javascript and What is the use for Properties In JavaScript . In object-oriented programming languages class have 3 types of properties Read/ Write properties Read-only properties Write only properties class Employee string _name; int _salary; public Employee(string name,int salary) _name=name; _salary=salary; //read/write proerties public int salary getreturn _salary; set_salary=value; //read only property public string nameget; //write only property public string emailset; Why we need properties? Encapsulation is one of the pillar of object-oriented programming. Properties provide encapsulation. If you provide public fields you can not have more control over it but if you use properties then you have control. function Employee(salary) this.Salary=salary; var emp=new Employee(-1); In the above example, we are setting salary =-1 which is wrong to overcome this kind of situation we requ...