Question about accessing object properties in javascript

12 Views Asked by At

I just started learning javascript using codecademy and I'm doing a quiz on object properties.

One of the questions is as follows:

"Which of the following lines of code would print the value saved to the _num key in the tempObj object?"

The code is:

let tempObj = {
    _num: 22,
    get num() {
       return this._num;
  }
};

One of the correct answers was console.log(tempObj['num']);

However, I'm confused by this because wouldn't adding the quotation marks around 'num' make the computer evaluate it as a string rather than as a getter? If not, why not?

0

There are 0 best solutions below