JSFiddle - React, Tailwind, and code Playground

JavaScript

function scopedEval(str, scope) {
   var f = new Function("scope", "with(scope) { return (" + str + "); }");
   return f(scope);  
}

var scope = { first:1, second:2 };

var expr1  = "second || first";
var expr2  = "third || second || first";

alert( scopedEval(expr1,scope) );
alert( scopedEval(expr2,scope) );