Get “variable” name as a string in JavaScript
1 min readSep 13, 2020
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: