Home >Web Front-end >JS Tutorial >How to use the new es6 syntax?

How to use the new es6 syntax?

零下一度
零下一度Original
2017-07-21 17:38:481739browse

Introduction

ES6 is a new generation standard for JavaScript language, which adds some new functions and syntax. It was officially released in June 2015, also known as ES2015; this standard is approved by ECMA ES7 is being formulated by Technical Expert Committee No. 39 (TC39) of the European Computer Manufacturing Federation and is said to be released in 2017.

1. Declare variables:

let declares variable scope code block scope {}. If the module is used first and then declared, an error will be reported

 {      let a= 12;      alert(a)    }
  let 不允许重复声明同一个变量 
  
  const 声明是一个常量,一旦被赋值就不允许修改 作用域在代码块内 没有变量的预解析 不支持先声明后解析      {        const a = 12;        console.log(a);   }

2. Characters String

String template ${}

 var str1  = 'to';   console.log(`welcome ${str1} china`)
   
     //includes() 是否包含,返回true/false ;区分大小写     console.log(str.includes('ED'))   console.log(str.startsWith('ED'))//开头是否包含要找的字母区分大小写     console.log(str.endsWith('ED'))//开头是否包含要找的字母区分大小写
     var str2 = str.repeat(3);   //重复复制几个

3. Array:

			var arr1 = [1,2,3];
//			arr1.pop();
//			var arr2 = arr1;
//			console.log(arr2);
			
//			var arr2 = Array.form(arr1) //form()全新拷贝的方法
//			console.log(arr2)

var arr1 = [1,2,3];
var arr2 = [...arr1];//[...quote]
console.log(arr2)

The above is the detailed content of How to use the new es6 syntax?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn