Communities for your favorite technologies. Explore all Collectives
Ask questions, find answers and collaborate at work with Stack Overflow for Teams.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams
Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
I have a code saved in string. For eg: const code = "res.send("Hi")"; How can I execute the above code in JS? I wanna execute the code of the code variable. I can't just write code;. The code doesn't execute. Please Help.
const code = "res.send("Hi")";
code
code;
eval(code)
.to()
use eval
eval
const code = "console.log('Hi')"; eval(code)
Add a comment
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
eval(code)- but be careful, that is risky..to()so you don't have to use a string. Having it in a string is not the way to go here.