- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
- Related Articles
- What is the “get” keyword before a function in a class - JavaScript?
- Class Keyword in JavaScript
- What is the keyword used in instantiating a class in Java?
- What is a class in JavaScript?
- What is the yield keyword in JavaScript?
- What does the exclamation mark do before the function in JavaScript?
- What happens when a function is called before its declaration in C?
- What is the 'new' keyword in JavaScript?
- What is the usage of yield keyword in JavaScript?
- How to get the return value from a function in a class in Python?
- What is the purpose of the var keyword in JavaScript?
- What is a function literal in JavaScript?
- What is a fat arrow function in JavaScript?
- First class function in JavaScript
- When should I use the keyword ‘this’ in a Java class?
- What is a standard for commenting a function in JavaScript?

Advertisements