Skip to content Skip to sidebar Skip to footer

Dynamic Variables In Javascript

What is the use of Dynamic variables? Any scenarios? Can I attach this value to a TextField? var data = 'testVariable'; eval('var temp_' + data + '=123;'); alert(temp_testVariabl

Solution 1:

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.

Solution 2:

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.

Post a Comment for "Dynamic Variables In Javascript"