-1

I have a String that contains a function as a String. This String is returned by the server:

var funcStr = "function() {
    console.log('this is a sample function');
}";

Is it possible to parse this String to a Function and execute it?

Philipp
  • 15,377
  • 4
  • 35
  • 52
Marc Gil Sendra
  • 819
  • 2
  • 9
  • 22

1 Answers1

1

Yes, it is possible, but not a good idea. You use eval. This isn't the best to do for reasons too complex and opinion-based to get into here.

Feathercrown
  • 2,547
  • 1
  • 16
  • 30