Why I got undefiend value?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why I got undefiend value??

var obj={ namee:'aniket', full:`my name is ${this.namee}` } console.log(obj.full)

26th Sep 2021, 3:35 AM
Aniket Ganguly
1 Answer
+ 3
Getting another variable is a functional job. Object key:value can't perform functional return. You need to create function to call. var obj={ namee:'aniket', full: function() { return `my name is ${this.namee}`; } } console.log(obj.full()); Or use getter to get a function call return value. var obj={ namee:'aniket', get full() { return `my name is ${this.namee}`; } } console.log(obj.full); https://code.sololearn.com/ch5FdbgSmK2O/?ref=app
26th Sep 2021, 5:16 AM
Calviղ
Calviղ - avatar