Click here to Skip to main content
14,875,917 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Everyone

I am having javascript variable


JavaScript
var str = "function(){alert('Hello')}";


I want to execute the function inside the string.

Is this possible to execute the function inside the string


Any suggestion or helping material will be highly appreciated


Regards
Posted
Comments
Sinisa Hajnal 8-Sep-14 8:37am
   
You really shouldn't have such variables.

1 solution

JavaScript
eval("your-script");

eval() MDN[^]
[edit]added link[/edit]
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900