Earlier ECMAScript versions were named by numbers, such as ES5 and ES6. Starting in 2016, versions are named based on the release year, like ES2016, ES2018, ES2020, and so on.
ES2019 introduced the trimStart() method in JavaScript. It works similarly to trim(), but removes whitespace only from the beginning of a string.
let text1 = ” Hello World! “; let text2 = text1.trimStart(); |
The JavaScript String.trimStart() method has been supported in all modern browsers since January 2020.
ES2019 introduced the Object.fromEntries() method in JavaScript. This method creates an object from iterable key-value pairs.
const fruits = [ [“apples”, 300], [“pears”, 900], [“bananas”, 500] ]; const myObj = Object.fromEntries(fruits); |
The JavaScript Object.fromEntries() method has been supported in all modern browsers since January 2020.
Starting with ES2019, you can omit the catch
parameter if it is not needed.
Before 2019:
try { // code } catch (err) { // code } |
After 2019:
try { // code } catch { // code } |
Optional catch binding has been supported in all modern browsers since January 2020.
ES2019 introduced the Array.flat() method in JavaScript. This method creates a new array by flattening a nested array.
const myArr = [[1,2],[3,4],[5,6]]; const newArr = myArr.flat(); |
The JavaScript Array.flat() method has been supported in all modern browsers since January 2020.
ES2019 introduced the Array.flatMap() method in JavaScript.
This method first maps all elements of an array, then creates a new array by flattening the result.
const myArr = [1, 2, 3, 4, 5, 6]; const newArr = myArr.flatMap(x => [x, x * 10]); |
ES2019 revised the Array.sort()
method to require a stable sorting algorithm.
Prior to ES2019, the specification allowed unstable algorithms like QuickSort. After ES2019, browsers must use a stable sorting algorithm, ensuring that elements with the same value maintain their relative positions.
const myArr = [ {name:“X00”,price:100 }, {name:“X01”,price:100 }, {name:“X02”,price:100 }, {name:“X03”,price:100 }, {name:“X04”,price:110 }, {name:“X05”,price:110 }, {name:“X06”,price:110 }, {name:“X07”,price:110 } ]; |
In the example above, when sorting by price, the names should retain their original relative positions if their prices are the same, ensuring a stable sort.
X01 100 X03 100 X00 100 X03 100 X05 110 X04 110 X06 110 X07 110 |
ES2019 revised the JSON.stringify() method to allow characters encoded with a backslash (\) to be properly stringified, which was not possible before 2019.
let text = JSON.stringify(“\u26D4”); |
Before ES2019, using JSON.stringify() on UTF-8 code points (U+D800 to U+DFFF) would result in broken Unicode characters, like ���.
With the ES2019 revision, strings containing these UTF-8 code points are now safely converted with JSON.stringify() and can be accurately restored using JSON.parse().
Before 2019, line separator and paragraph separator symbols (\u2028 and \u2029) in string literals were treated as line terminators, causing errors. After the revision, these characters are now allowed in string literals without causing exceptions.
// This is valid in ES2019: let text = “\u2028”; |
NoteBefore ES2019: JSON.parse(‘”\u2028″‘) would return an empty string (”). ‘”\\u2028″‘ would result in a syntax error. After the revision, JavaScript and JSON follow the same rules, allowing these characters to be parsed and used correctly. |
ES2019 revised the Function.toString() method. Prior to 2019, different browsers returned variations of a function’s source code, often omitting comments, spaces, or formatting.
From 2019 onwards, toString() must return the function’s source code exactly as written, including comments, spaces, and all syntax details.
function myFunction(p1, p2) { return p1 * p2; } |