📜  如果 eval js 中存在无效表达式,那么如何获取 ti - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:16.703000             🧑  作者: Mango

代码示例1
function myFunction() {
    var x = 10;
    var y = 20;
    var res;

    try {
        var a = eval("x * y") + "
"; var b = eval("2 + 2") + "
"; var c = eval("x + 17") + "
"; var d = eval("x + 17 + ") + "
"; res = a + b + c; } catch (e) { res = 'Expression in invalid.'; } $("#demo").html(res); }