Chapter 37: JS & TS Features

JavaScript & TypeScript features that matter most when working with Node.js (especially in 2025–2026).

I will speak as if we are sitting together in a coding session — I’m showing you code, explaining why this feature is useful, when you should reach for it, what problems it solves, what common mistakes people make, and how real Node.js developers use it today.

We will cover the features in rough order of importance for modern Node.js backend work.

1. Top-level await (the single biggest game-changer since async/await)

What it is You can now use await directly at the top level of a module (no need to wrap everything in an async function).

When Node.js got it Fully stable since Node.js 14.8 (2020), widely used since ~Node 16–18.

Why it is so important for Node.js

Before top-level await:

JavaScript

After top-level await (clean & beautiful):

JavaScript

Real-world patterns you see everywhere in 2025–2026

TypeScript

Very important gotcha

Top-level await only works in ES Modules (“type”: “module” in package.json or .mjs files).

2. ESM – import / export (you should already be using this)

Quick checklist what you should be doing in 2025–2026

JSON
TypeScript

Modern patterns

TypeScript

Very useful trick – dynamic import

TypeScript

3. Optional chaining (?.) & Nullish coalescing (??)

These two operators alone remove ~30–40% of defensive code in real Node.js projects.

TypeScript

Very common Node.js patterns

TypeScript

Pro tip ?? is much better than || for defaults because:

TypeScript

4. Destructuring + rest / spread – everywhere

TypeScript

Very powerful pattern – rename + default + rest

TypeScript

5. Template literals + tagged templates

TypeScript

Popular libraries that use tagged templates:

  • @prisma/client raw queries
  • sql-template-strings
  • common-tags
  • dedent
  • clsx / tw-merge for classnames

Very common pattern

TypeScript

6. Logical assignment operators (very clean)

TypeScript

Very useful in config files

TypeScript

7. Private class fields & methods (#private)

TypeScript

Very common in services & ORMs

TypeScript

8. Quick summary table – most important features for Node.js in 2025–2026

Feature Why you should use it in Node.js Typical line of code example
Top-level await Clean startup scripts, config loading const db = await connectDb();
ESM (import/export) Future-proof, tree-shakable, same syntax as frontend import { prisma } from ‘./prisma.js’
Optional chaining + ?? Removes 30–50% of defensive code user?.profile?.address?.city ?? ‘Unknown’
Destructuring + rest/spread Clean extraction, immutable updates const { password, …safe } = user
Template literals + tagged SQL, HTML, CLI output, classnames sqlSELECT * FROM users WHERE id = ${id}
Logical assignment ( =, ??=)
Private fields (#) Real encapsulation, better refactoring safety class { #secretKey: string }
structuredClone Deep copy objects (native since Node 17) const copy = structuredClone(original)

Which feature would you like to explore much deeper next?

  • Full top-level await startup patterns (config, DB, server)
  • Realistic ESM project structure with barrel files, aliases, dynamic imports
  • Writing tagged template literals (SQL, HTML, CLI output)
  • Using private fields + TypeScript in services / domain models
  • Modern configuration loading patterns with top-level await + zod

Just tell me what interests you most — I’ll continue with very concrete, production-ready examples. 😊

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *