ES也是一門腳本語言,一般看做JavaScript的標準化規範,實際上JavaScript是ECMAScript的擴展語言
ECMAScript 和 JavaScript 的關係是,前者是後者的規格,後者是前者的一種實現(另外的 ECMAScript 方言還有 JScript 和 ActionScript)segmentfault
JS在瀏覽器環境下,JS = WEB + ES數組
JS在Node環境下 JS = Node + ES瀏覽器
版本迭代安全
文章入口數據結構
文章入口函數
ES2015爲字符串添加了Iterator。因此字符串能夠for...of..
遍歷
模板字符串this
傳統字符串不支持換行 \nspa
const str = `hello es2015 this is made in China` console.log(str); //會輸出空行 const name = "tom" const msg = `hello ${name}` //插值表達式 console.log(msg);
標籤模板翻譯
//模板字符串前能夠添加標籤,是個方法 ["hello world"] const tag = console.log`hello world`
const n = "mcgee" const bol = true function myTagFnc(arr,n,bol){ //參數爲靜態內容,插值,插值... console.log(arr,n,bol); //['hey,','is a','.'] 靜態內容的分割 //標籤的做用,對值進行加工 const sex = bol?"man":"woman" // return 123 return arr[0]+n+arr[1]+sex+arr[2] } const result = myTagFnc`hey,${n} is a ${bol}.` console.log(result); //123 || hey,mcgee is a true || hey,mcgee is a man
對插值進行加工。文本的多語言化,翻譯成中英文。檢查模板字符串內的不安全字符code
const msg = 'Mcgee is a man' console.log(msg.startsWith("Mcgee")) //true console.log(msg.endsWith("n")); //true console.log(msg.includes("is")); //true
'na'.repeat(0) // "" 'na'.repeat(2.9) // "nana" 'na'.repeat(Infinity) // RangeError 'na'.repeat(-1) // RangeError //若是repeat的參數是字符串,則會先轉換成數字。 'na'.repeat('na') // "" 'na'.repeat('3') // "nanana"
Number.isInteger(25) // true Number.isInteger(25.0) // true Number.isInteger(25.1) // false Number.isInteger() // false Number.isInteger(null) // false Number.isInteger('15') // false Number.isInteger(true) // false