In JavaScript is there a way to get the "value" of a statement in the same way that function() { return eval("if (true) { 1 }"); }
returns "1";
function() { return if (true) { 1 } }
and all similar permutations I've tried are not valid syntax.
Is eval
just blessed with special powers to determine the "last" value of a statement in an expression?
Use case is a REPL that evaluates arbitrary expressions and returns the result. eval works, but I want to wrap it in function.