javascript - Can you set a variable name equal to another variable's value? -
i interested in knowing if possible.
one example variable exists.
foo = 1; var bar = 'foo'; if('foo' == 1)?
is there way that.
is there way bar == foo.variablename
yes can wouldn't recommend it.
s="unicorn" eval("var " + s + " = 'test'") alert(unicorn)
but text in question kind of sounds want check if variable exists , possible
if (typeof variable == "undefined") alert("it's not defined!");
Comments
Post a Comment