我有以下带有反引号和$ {expr}的ES6标记模板字符串:
`{ Some number is ${someNumber} }`
变量someNumber
为30,字符串输出Some number is 30
如何将1加到someNumber
以获得31?
我尝试过:
`{ Some number is ${someNumber + 1} }`
但是得到The number is 301
也
`{ Some number is ${someNumber} + 1}`
获取:The number is 30 + 1
我正在尝试获取Some number is 31
答案 0 :(得分:4)
someNumber
可能是一个字符串,在添加1之前将其转换为数字(我使用过plus运算符)。
const someNumber = '30';
const str = `{ The number is ${+someNumber + 1} }`;
console.log(str);
答案 1 :(得分:1)
尝试一下:
marks = c(171959, 429897, 509702, 581455, 862469)
hist(net.worth$`Net Worth`, main="Net Worth", xlab="Net Worth", xaxt='n', ylab="Customers", col="light blue")
axis(1, at=marks, labels=marks)