title: Validate that a string is valid JavaScript
body: <p>I am creating a website that will demonstrate the dangers of XSS. Users will attempt to get JavaScript to execute using an XSS vulnerability. </p>
  
  <p>However, I am running into problems in determining if JavaScript is actually being executed so that I can record that the user was successful. I will be running these checks on a node.js server. </p>
  
  <p>I originally planned to run <code>eval</code> on the parts which would contain JavaScript if the user was successful, but thought that this would be too dangerous as it would be running on the server-side and could get the server exploited. </p>
  
  <p>Are there any ways to using JavaScript to validate if a string is valid JavaScript other than running eval? Or is there a way to run <code>eval</code> without putting my server at risk?</p>