I have the following bit of code
console.log(\"I am\"); var x = \"console.log(\'Alive!\')\";
Now I only want to use x to exec
x
What you are looking for is called a function:
function x() { console.log('Alive!'); }
If x is already a string containing the code you could use eval(x) to execute it. eval is evil though.
eval(x)
eval