search

Home  >  Q&A  >  body text

javascript - How to use the character "+" as a real plus sign

x = "-";
console.log("5" + x + "" + "2");
过去多啦不再A梦过去多啦不再A梦2748 days ago616

reply all(3)I'll reply

  • 淡淡烟草味

    淡淡烟草味2017-05-24 11:39:05

    var x = '-'
    console.log(new Function('return ' + "5" + x + "" + "2")())

    reply
    0
  • PHP中文网

    PHP中文网2017-05-24 11:39:05

    x = '-'; eval(Number(5) + x + '' + Number(4))

    Try this

    x = '-'; eval('5' + x + '' + '4')

    This is also possible

    reply
    0
  • 怪我咯

    怪我咯2017-05-24 11:39:05

    Complain about where this demand comes from and try to avoid this kind of strange demand

    Upstairs is a practice

    I provide another one here
    '1+1'.match(/([0-9]+)(-|+)([0-9]+)
    The specific idea is to use regular expressions to match numbers and operators, and then use switch to match the operators to return different results

    In addition, if the questioner is studying, I still don’t recommend this weird approach. No one will like this way of writing

    reply
    0
  • Cancelreply