How to interpolate variables in strings in JavaScript, without concatenation?

前端 未结 16 2613
长情又很酷
长情又很酷 2020-11-22 02:41

I know in PHP we can do something like this:

$hello = \"foo\";
$my_string = \"I pity the $hello\";

Output: \"I pity the foo\"<

16条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-22 03:08

    Simply use:

    var util = require('util');
    
    var value = 15;
    var s = util.format("The variable value is: %s", value)
    

提交回复
热议问题