Get & Set
This lesson teaches how to use the "get" and "set" keywords in JavaScript.
We'll cover the following...
Using get
Keyword
In the previous lesson the following code was discussed:
Press + to interact
var employee = {name: 'Joe',age: 28,designation: 'developer',//function returning designation of the employeedisplay() {return this.designation //using this to refer to the "employee" object}}//this will display the designationconsole.log(employee.display())
Here the function display()
was being used to get the value of the property designation
. Another way to do this by using the get
keyword.
Example
Let’s take a look at an example implementing the get
...
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy