Convert string to JavaScript source code [duplicate]

1

For example, if I have a string variable that stores ', how can I run it or convert it to source code?

    
asked by anonymous 03.01.2018 / 16:50

1 answer

3

You can use eval () that evaluates (and executes) the code represented in a string. Example:

var comm = "alert('teste');";
eval(comm); //Executa o alert
    
03.01.2018 / 16:56