ES6 模板字符串(template string)

模板字符串(template string)

绑定变量${}

    var name="ssss"
	var age="3"

	var lian='my name is'+name+'i am'+age;
	console.log(lian);//my name isssssi am3

	var lian1=`my name is${name}i am${age}`;
	console.log(lian1)//my name isssssi am3

	let  a=1;
	let  b=2;
	let abb=`${a}+${b}=${a+b}`;
	console.log(abb);//1+2=3

	let x = 1;
	let y = 2;
	let sumTpl = "" + x + " + " + y + " = " + (x + y);

	console.log(sumTpl); // 1 + 2 = 3

支持多行和换行

let shi = `chun
			xia
			qiu
			dong`;
			console.log(shi); // chun
			                    // xia
			                    // qiu
			                    // dong			                    

	//普通数组不支持多行或换行
	//加/n 可以换行			                    
	let shi1= "chun \n xia \n qiu \n dong"
	console.log(shi1)// chun
				    // xia
				    // qiu
				    // dong
posted @ 2017-07-11 19:50  师妹儿  阅读(453)  评论(0编辑  收藏  举报