Skip to content

Latest commit

 

History

History
73 lines (54 loc) · 1.69 KB

4-ES10.md

File metadata and controls

73 lines (54 loc) · 1.69 KB

ES10 new features:

  • Array#{flat,flatMap}

  • Object.fromEntries

  • String#{trimStart,trimEnd}

  • Symbol#description

  • try { } catch {} // optional binding

  • JSON ⊂ ECMAScript
    Extend ECMA-262 syntax into a superset of JSON.

  • well-formed JSON.stringify
    To prevent JSON.stringify from returning ill-formed Unicode strings.

  • stable Array#sort
    Array.Sort Stability

  • revised Function#toString
    The toString() method returns a string representing the source code of the function.Earlier white spaces,new lines and comments will be removed when you do now they are retained with original source code


  • Array#{flat,flatMap}
let list = ['a', ['b', ['c', ['d']]]]
console.log(list.flat()); // ["a", "b", Array(2)]
console.log(list.flat(2)); //  ["a", "b", "c", Array(1)]
console.log(list.flat().flat()); //  ["a", "b", "c", Array(1)]
console.log(list.flat(Infinity)); // ) ["a", "b", "c", "d"]
a = list.flat(Infinity).flatMap(v => v.split(''))
console.log(a); // ["a", "b", "c", "d"]
  • Object.fromEntries()
const log = console.log
let a = Object.fromEntries([['a', 1], ['b', ['bb']]])
console.log(a); // ( a: 1, b: ["bb"] }
a = Object.fromEntries([['a', 1], ['b', 'cc']])
console.log(a); // {a: 1, b: "cc"}
  • String#{trimStart,trimEnd}
let str = '    abcdefg   '
console.log(str.trimStart()); // abcdefg   
console.log(str.trimEnd()); //      abcdefg
console.log(str.trimRight()); //     abcdefg
console.log(str.trimLeft()); // bcdefg
  • Symbol#description

  • try {} catch{} // optional error binding

try {
    throw Error('catch un error aca!')
} catch {
    console.error('error!!')
}