I know how to check whether a variable in Javascript exists or not. I can simply use
if (variable == null) { // do something }
to check that it does not exist. Or similarly
if (typeof variable == 'undefined') { // do something }
But I'm in a slightly different situation: I have a variable named 'myVariable' which takes a string as value.
Question: How can I check whether a variable exists with a name equal to the value of myVariable?
Example: If we have
var myVariable = 'car';
how can I check whether a variable exists / is defined with the name 'car'? (Of course in practice we don't know the value of myVariable). I need something like
if (typeof value of myVariable == 'undefined') { // do something}
Thank you very much in advance for any help!