[JavaScript] features

2023

Array.prototype.findLast/findLastIndex

Polyfill:core-js / es-shims
arr.findLast(e => e.key === 1);

hashbang grammar

脚本语言第一行的 #!
#!/usr/bin/env node

'use strict';
console.log(1);

2022

proposal-class-fields

class A {
    x = "public field";
    #z = "private field"
    get y() { /* ... */ }
    set y(value) { /* ... */}
}

class B extends A {
    constructor() {
        super();
        // ...
    }

    static method() {
        // ...
    }
}

static class C {}

.at

// Array / String / TypedArray
arr.at(0) === a[0]; // true

Object.hasOwn

Object.prototype.hasOwnProperty.call(object, "foo");
// simplifies
Object.hasOwn(object, "foo");

Error.cause

new Error('Failed', { cause: err });

2021

String.prototype.replaceAll

numeric separators

const num = 1_234_567;

Promise.any()

Logical Assignment

||=
&&=
??=

weakrefs

💥与WeakMap联合使用,参加 [JavaScript] 内存管理

2020

String.prototype.matchAll

BigInt

globalThis

optional chaining operator (?.)

2019

Array.prototype.{flat, flatMap}

string trimming

2018

Asynchronous Iterators

object rest/spread properties Promise.prototype.finally

2017

Object.{values, entries}

String padding

async functions

shared memory and atomics

2016

exponentiation (**) operator Array.prototype.includes

2015

Syntax

function fn(params = defaultParams) {}

// arrow fn
const arrowFn = (...restParams) => {};

// bindings
// rest & spread
const [...arr] = [];
const {...obj} = {};
const arr0 = [...arr];
const obj0 = {...obj}
for ... of loops

// 二/八/十六进制
0b11 === 3
011 === 9
0x11 === 17

// template literals
`string ${literal}`

functions

// arrow fn
const arrowFn = (...restParams) => {};

class Demo {

    // generators
    *keys() {
        yield "key";
    }
}

built-ins

type arrays Map / Set / WeakMap / WeakSet Proxy / Reflect Promise Symbol

Date:
Words:
237
Time to read:
1 min