Reputation: 391
How can I evaluate (to true or false) a logical expression stored in a var as a string, without using eval()?:
var test = '(1 < 2 || 2 < 1) && 1 < 0)'
Upvotes: 0
Views: 430
Reputation: 1
var test = '((1 < 2 || 2 < 1) && 1 < 0)';
console.log(new Boolean(new Function(`return ${test}`)()));
Upvotes: 3