Can I get the "value" of an arbitrary statement in JavaScript (like eval does, but without eval)

Posted by tlrobinson on Stack Overflow See other posts from Stack Overflow or by tlrobinson
Published on 2010-03-17T00:17:12Z Indexed on 2010/03/17 0:21 UTC
Read the original article Hit count: 759

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about eval