
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Using the get in JavaScript to make getter function
Use get keyword to make getter function.
Example
Following is the code −
const studentDetails = { studentName: "David Miller", get studentName() { console.log('I am calling the getter method...') } } console.log(studentDetails.studentName);
To run the above program, you need to use the following command −
The output is as follows −
node fileName.js.
Here, my file name is demo221.js.
Output
The output is as follows −
PS C:\Users\Amit\JavaScript-code> node demo221.js I am calling the getter method... Undefined
- Related Questions & Answers
- How to delete a getter using the delete operator in JavaScript?
- How to define getter and setter functions in JavaScript?
- What is the difference between getter and setter in JavaScript?
- Getter and Setter in Python
- How to make a text italic using JavaScript?
- How to get the clipping rectangle using imagegetclip() function in PHP?
- Getter and Setter in Dart Programming
- How to get the current time in millisecond using JavaScript?
- How to define a JavaScript function using the expression?
- How to make your code faster using JavaScript Sets?
- Removing letters to make adjacent pairs different using JavaScript
- How to define a JavaScript function using Function() Constructor?
- Override getter for Kotlin data class
- Make a custom function call without using SAP NetWeaver
- How to write a JavaScript function to get the difference between two numbers?
Advertisements