So I really couldn't find much on this. The idea is that I have a user input (text) and I want to check if its valid code in JS and then run it if it is.
I know that I can do if (typeof userInput === "function") {
if the userInput
was actually a function, but the user input is just a string input at this point, so I'm quite stuck, and it also contains any arguments or other code.
As an example, the input may be "alert('test')"
and that would be valid, and I would like to run that, however something like "madeUpFunction(lol)"
would be invalid.
I'm happy if I can just get functions working and not any JS code.