JSX ES6向标记的模板字符串添加+1

时间:2018-10-06 21:00:35

标签: javascript ecmascript-6 jsx

我有以下带有反引号和$ {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

2 个答案:

答案 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)