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
  • 157,677
  • 23
  • 242
  • 245
陆仁贾
  • 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
  • 72,912
  • 30
  • 168
  • 299