Template literals are string literals allowing embedded expressions. You can use multi-line strings and string interpolation features with them. They were called "template strings" in prior editions of the ES2015 specification. http://es6.ruanyi…
1.es6中变量声明可以使用let声明变量,用const声明常量.例: test:function(){ { var num=10; let num1=11; const num2=12; } console.log(num); console.log(num1); //报错 console.log(num2); //报错 } 2.es6中的模板字符串.使用反撇号字符`代替普通字符串的引号'或".例: test:function(){ var num=12; var num1=15; var s…
字符串拼接是在日常开发中必不可少的一个环节. 注意:字符串可以用单引号'',或者""双引号,出于方便大家理解,文章以下内容统一使用单引号''! 如果只是一个字符串和一个变量拼接,使用传统的字符串拼接就没什么问题,只需要一个+号和一个''号就好了:但是有时候会有多个字符串与变量拼接,那么就会有一大堆的+号和''号,造成代码不美观. 1. 传统的字符串拼接 var name = 'moss'; ; console.log('My name is ' + name + ' and I am…
在线编译器:babel.github 在nongjs中使用 'use strict' let a = ; 运行node : node --harmony_destructuring xxx.js 代码块: 用{}包起来的代码块,比如 if for while 特点:只能在代码块里面使用 var 只有函数作用域,可以重复声明, let const 有块级作用域,不可重复声明 封闭空间 ES5: (function() { ; })(); ES6: { let a = ; } 总结:块级作用域,其实…
目录 字符串拼接 includes() startsWith() endsWith() padStart() es6中的模版字符串替代了原有的字符串拼接功能. 字符串拼接 es5方式 传统的字符串拼接在变量的左右两侧都要有+号连接. let name = '张三'; let age = 9; let str = '我的名字叫' + name + '我今年' + age + '岁了'; console.log(str)//我的名字叫张三我今年9岁了 如果你还想在这个字符串中加入空格回车或者其他的特…
es6中一些基本的使用方法 const 定义常量 let 块级变量 用let定义的变量只在块当中起作用,离开变量外界的块(括号)就会被销毁. 模板字面量 用于字符串拼接和写模板,使用 ` (反引号,左上角波浪线),变量使用${} 1 var a="大帅比"; 2 var b="你呢"; 3 console.log( `my name is ${a},${b}?` ); //my name is 大帅比,你呢? 4 5 var tpl=`<ul class=&q…