Top-level await
await myFunction()
Object.hasOwn()
const myObject = {
name: 'dav1',
age: 28
}
Object.hasOwn(myObject, 'name')
Error cause
const parentError = new Error('Parent error')
const childError = new Error('Child error', { cause: parentError })
[1,2,3,4,5,6].at(-2)
Set
const arrayWithDuplicates = [1,2,3,4,4,4,5,6,7]
const mySet = New Set(arrayWithDuplicates)
const arrayWithoutDuplicates = [...mySet]
Temporal
const myDate = Temporal.now.plainDateISO()
console.log(myDate)
console.log(myDate.add({ days: 2 }))
Array.findLast() and Array.findLastIndex()
const userData = [{
name: 'John',
age: 23
},{
name: 'Maria',
age: 34
},{
name: 'John',
age: 33
}
]
userData.findLast(user => user.name === 'John')
userData.findLastIndex(user => user.name === 'John')
Throw Expressions
function addDays( date = throw new TypeError("Argument required")) {
}
Import()
const modules = await import("module-name");
Pipeline
const a = 4
a |> multiplyBy2(^) |> addFour(^) |> addOne(^)
Logical Nullish Assignment
let a = 10
a ??= 14
console.log(a)
let b = undefined
b ??= 14
console.log(b)
Numeric separators
const a = 1_000_000
String.replaceAll()
let a = 'money money money car money'.replaceAll('money', 'bees')
Records and Tuples
const a = #{
b: 'This cannot be changed!'
}
const b = #[1,2,3,'This cannot be changed either']
Optional catch binding
try {
doSomething();
} catch {
handleException();
}
Module Blocks
const moduleBlock = module {
export async function main(url) {
return import.meta.url;
}
}