Len*_*ico 16 javascript variables
我想加入一个js变量和另一个变量来创建另一个变量名...所以它看起来像;
for (i=1;i<=2;i++){
var marker = new google.maps.Marker({
position:"myLatlng"+i,
map: map,
title:"title"+i,
icon: "image"+i
});
}
Run Code Online (Sandbox Code Playgroud)
后来我有
myLatlng1=xxxxx;
myLatlng2=xxxxx;
Run Code Online (Sandbox Code Playgroud)
Lig*_*ica 33
使用连接运算符 +,以及数字类型将自动转换为字符串的事实:
var a = 1;
var b = "bob";
var c = b + a;
Run Code Online (Sandbox Code Playgroud)
var variable = 'variable',
another = 'another';
['I would', 'like to'].join(' ') + ' a js ' + variable + ' together with ' + another + ' to create ' + [another, ...[variable].concat('name')].join(' ').concat('...');
Run Code Online (Sandbox Code Playgroud)
ES6 引入了用于连接的模板字符串。模板字符串使用反引号 (``) 而不是我们习惯于使用常规字符串的单引号或双引号。因此,模板字符串可以写成如下:
// Simple string substitution
let name = "Brendan";
console.log(`Yo, ${name}!`);
// => "Yo, Brendan!"
var a = 10;
var b = 10;
console.log(`JavaScript first appeared ${a+b} years ago. Crazy!`);
//=> JavaScript first appeared 20 years ago. Crazy!
Run Code Online (Sandbox Code Playgroud)