The following works fine:
var scope = {};
math.eval('f(x) = x^2', scope);
scope.f(3); // 9
but when having a multiline expression containing a function definition, we get an error:
var scope = {};
math.eval('a=2; f(x) = x^a', scope);
// Uncaught SyntaxError: missing ) after argument list
The following works fine:
but when having a multiline expression containing a function definition, we get an error: