0

I just found out that when I want to use this in a javascript object value, it doesn't work. I just want to use a value inside of my object for another value but it just set it as undefined and idk how to fix it.

thi is the code i was typing :

let obj1 = {
    name : 'Omid',
    nickName : 'Gh',
    age : 23,
    yearOfBirth : this.nickName,
}

console.log(obj1);

I expected to set " yearOfbirth " value as a number and set it to 23, but it didn't and set it as undefined in the object. Although when I logged the type of obj1.age, it just showed me " number " and it was true.

Omid gh
  • 1
  • 2

0 Answers0