0

I have

let name = 'enzo'
let age = 20

if I log name console.log(name) and age console.log(age), it will show

enzo
20

but I expected to this effect

console.log("name:",name)
console.log("age:",age)

it will show

name: enzo
age: 20

so how can I get the name of variable?

Phil
  • 141,914
  • 21
  • 225
  • 223
陆仁贾
  • 21
  • 3

1 Answers1

7

One option is to use shorthand property names in object initializers:

let name = "enzo";
let age  = 20;

console.log({name});
console.log({age});

Does that solve your problem?

Aadit M Shah
  • 70,635
  • 28
  • 161
  • 285