ES6新特性 學習總結

2021-09-05 09:41:49 字數 421 閱讀 8443

let s = 'hello world!';

s.startswith('hello') // true

s.endswith('!') // true

s.includes('o') // true

這三個方法都支援第二個引數,表示開始搜尋的位置。

let s = 'hello world!';

s.startswith('world', 6) // true

s.endswith('hello', 5) // true

s.includes('hello', 6) // false

上面**表示,使用第二個引數n時,endswith的行為與其他兩個方法有所不同。它針對前n個字元,而其他兩個方法針對從第n個位置直到字串結束。

es6新特性 ES6新特性(一)

var 1 var宣告的是函式作用域 區域性 但在if for等定義的變數是全域性的 2 var 具有變數提公升,預解析 3 在同乙個作用域下,var可以宣告多次 4 var 宣告的變數會掛載到window上 let1 let不存在變數提公升,在變數使用之前,必須要先宣告 2 let在同一作用域下,...

ES6新特性須知

1.1es5之前函式想要賦預設值var funes5 function a,b,c 1.2es6開始函式想要賦預設值var funes6 function a 50,b 60,c 70 2.1es5之前字串拼接或者拼接屬性值只能如下var a lbj var b 50 var c name a ye...

es6新特性分享

1 字串查詢 es5使用是indexof 返回字元第一次出現的位置int值 es6新增了3個方法 includes startswith endwith 返回bool值 includes 是否包含字元 startswith 首字母是否包含字元 endwith 末尾是否包含字元 2 數值擴充套件 nu...