gpt4 book ai didi

javascript - 如何将变量放入 javascript 字符串中?

转载 作者:IT老高 更新时间:2023-10-28 21:47:10 25 4
gpt4 key购买 nike

s = 'hello %s, how are you doing' % (my_name)

这就是你在 python 中的做法。你怎么能在 javascript/node.js 中做到这一点?

最佳答案

使用 Node.js v4 ,你可以使用 ES6 的 Template strings

var my_name = 'John';
var s = `hello ${my_name}, how are you doing`;
console.log(s); // prints hello John, how are you doing

您需要将字符串包装在 `(反引号)而不是 '(撇号)中

关于javascript - 如何将变量放入 javascript 字符串中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7790811/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com