1
  1. What is the use of Dynamic variables? Any scenarios?
  2. Can I attach this value to a TextField?

    var data = "testVariable";
    eval("var temp_" + data + "=123;");
    alert(temp_testVariable);
    
5
  • 3
    None. Use hash maps (objects). Commented Jun 14, 2011 at 12:39
  • 3
    Why not use the slightly more acceptable window['temp_' + data] = '123';? Commented Jun 14, 2011 at 12:42
  • @josh.trow I'd say that that's a lot more than "slightly" more acceptable :-) Commented Jun 14, 2011 at 13:01
  • @Pointy: A mere technicality :) Commented Jun 14, 2011 at 13:09
  • stackoverflow.com/questions/35221108/… Commented Feb 7, 2016 at 9:17

2 Answers 2

6

What is the use of Dyanmic variables? Any Scenarious

For when people haven't heard of objects or arrays.

Can i attach this value to a TextField?

Yes.

Sign up to request clarification or add additional context in comments.

Comments

6

The answer to 2) is 'yes you can'.

However for 1), and overall, you probably shouldn't be using eval: Why is using the JavaScript eval function a bad idea?

As another comment and the currently upvoted answer says - either use arrays or a map.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.