Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

JavaScript Getter

const student = {

    // data property
    firstName: 'Monica',
    
    // accessor property(getter)
    get getName() {
        return this.firstName;
    }
};

// accessing data property
console.log(student.firstName); // Monica

// accessing getter methods
console.log(student.getName); // Monica

// trying to access as a method
console.log(student.getName()); // error
Comment

JavaScript Getter

const student = {
    firstName: 'Monica',
    
    //accessor property(setter)
    set changeName(newName) {
        this.firstName = newName;
    }
};

console.log(student.firstName); // Monica

// change(set) object property using a setter
student.changeName = 'Sarah';

console.log(student.firstName); // Sarah
Comment

PREVIOUS NEXT
Code Example
Javascript :: check if an array is empty 
Javascript :: lodash group by except group null items 
Javascript :: href before onclick js 
Javascript :: add jquery through consol 
Javascript :: register service worker 
Javascript :: javascript table show only first n rows 
Javascript :: load all icon from a folder in react 
Javascript :: appregistry react native 
Javascript :: passport google authentication node js 
Javascript :: how to make a bar graph in JS 
Javascript :: custom search filter in angular 8 
Javascript :: nodejs ERR_CONNECTION_REFUSED 
Javascript :: regex for fullstop 
Javascript :: Custom delay function for waitfor puppeteer 
Javascript :: sort array javascript 
Javascript :: orderbychild firebase react 
Javascript :: js addeventlistener keyup not working on phone 
Javascript :: empty string in javascript 
Javascript :: jquery how to expand select 
Javascript :: react form hook trigger is not a function 
Javascript :: what is undefined in javascript 
Javascript :: Extension server error: Object not found: <top, source: devtools://devtools/bundled/extensions/extensions.js (216) [9900:1226/171021.620 
Javascript :: post express node js input 
Javascript :: python restapi use post json 
Javascript :: ternary operator js 
Javascript :: how to update json key name while keeping the values in mysql 
Javascript :: angular inject token 
Javascript :: how to detect input value change by javascript observe 
Javascript :: sequelize documentation 
Javascript :: formgroup angular 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =