Get “variable” name as a string in JavaScript

amar kanala
1 min readSep 13, 2020

--

Photo by Jon Tyson on Unsplash

There might be a usecase to get variable name as a string, perhaps for logging purposes. We can do this by constructing object using shorthand and then pulling out the first property name with array destructuring

Here’s an example:

--

--