How do I parse and evaluate a mathematical expression in a string (e.g. \'1+1\') without invoking eval(string) to yield its numerical value?
\'1+1\'
eval(string)
Simple and elegant with Function()
Function()
function parse(str) { return Function(`'use strict'; return (${str})`)() } parse("1+2+3");