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

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -