freecoding.school100% FREE · NO SIGNUP
Closure CavesISSUE #59 of 61

ES2022 · top-level await · #private fields

LambdaVSThe Mutator
Lambda saysES2022 added top-level await, class #private fields, static blocks, and Array.at().

await now works at the top level of modules (no async wrapper needed). Classes gained true #private fields/methods and static {} initialization blocks. arr.at(-1) reads from the end (negative indexes). Object.hasOwn(obj, key) replaced the clunky hasOwnProperty call.

Power-ups you unlock

The Mutator attacks — common mistakes

Boss battleUse arr.at(-1) for the last item and Object.hasOwn for a safe key check.

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre id="o"></pre>
<script>const a=[10,20,30];const has=Object.hasOwn({x:1},'x');
document.getElementById('o').textContent='last='+a.at(-1)+' hasOwn(x)='+has;</script></body></html>
▶ Open the interactive comic issue
‹ ES2021 · ReplaceAll · Numeric SeparatorsES2023 · Array Find From Last · Symbol.Dispose ›