![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the “get” keyword before a function in a class - JavaScript?
The get keyword can be used as a getter function like C#, Java and other technologies.
We set a function with get like the following in a class −
class Employee { constructor(name) { this.name = name; } get fullName() { return this.name; } }
Example
Following is the code displaying an example of get −
class Employee { constructor(name) { this.name = name; } get fullName() { return this.name; } } var employeeObject = new Employee("David Miller"); console.log(employeeObject.fullName);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo299.js.
Output
This will produce the following output on console −
PS C:\Users\Amit\javascript-code> node demo299.js David Miller
Advertisements