Overview

1 JavaScript is everywhere

JavaScript has grown from a 10‑day browser scripting experiment into a ubiquitous language that powers websites, servers, desktop and mobile apps, and countless devices. Its rise is the story of continual evolution: faster engines, an active ECMAScript standards process, the advent of Node.js and a vast package ecosystem, and modern tooling that transformed the developer experience. TypeScript added static types and rich IDE support without changing JavaScript’s runtime, and this chapter sets the stage for mastering fundamentals first, then building toward “ninja” techniques for creating robust, performant software across environments.

At its core, JavaScript differs from many mainstream languages: functions are first‑class and pair with closures; objects are prototype‑based; and code runs on a single thread, leaning on callbacks, promises, and workers for asynchrony. Modern features—promises, advanced array methods, maps and sets, regular expressions, and modules—enable concise, expressive solutions. Code executes inside runtimes such as browsers and Node.js, atop engines like V8 and JavaScriptCore that JIT‑compile and expose host APIs. Because the language evolves yearly, developers balance new capabilities with runtime compatibility, using transpilers and polyfills where possible and testing where polyfills fall short, all while keeping an eye on how code maps to engine performance.

The chapter surveys today’s ecosystem and professional practices: web UI frameworks (with React’s JSX and virtual DOM and peers like Angular, Vue, and Svelte), server frameworks from minimalist to full‑featured, and full‑stack solutions that pair server‑side rendering with code‑splitting and a strong developer experience. Beyond the browser, app frameworks enable “write once, run anywhere,” from web‑view approaches like Electron and Ionic to React Native’s native components. It emphasizes best practices—TypeScript for type checking, ESLint and Prettier for code quality, and layered testing (unit plus end‑to‑end)—and tackles real‑world challenges: performance regressions from code bloat (mitigated by tree shaking, production flags, and lazy loading), collaboration at scale across teams (aided by module federation and codemods), and dependency risks, including supply chain concerns. With solid fundamentals and these techniques, you can build maintainable, high‑performance JavaScript in any domain.

How a JavaScript runtime brings JavaScript code to life.

Summary

  • JavaScript is everywhere. In addition to being the language of the web, it can be used to build applications for every major computing platform.
  • The JavaScript language has evolved dramatically over time, and continues to improve every year. However, depending on where you expect your code to run, you may need to transpile your code to take advantage of the latest features.
  • The vast majority of modern JavaScript projects are built using an open-source framework. Choosing the right framework for your project will give you a critical edge.
  • Best practices such as type checking, linting, and testing are key to writing robust, reliable code.
  • Some of the biggest challenges facing JavaScript developers are performance, collaboration at scale, and dependency management.
  • This book focuses on the core mechanics of the JavaScript language. Mastering those fundamentals will help you to architect, write, and maintain robust JavaScript applications.

FAQ

Why is JavaScript considered to be “everywhere” today?Because the language evolved far beyond the browser. Faster engines, a formal ECMAScript standards process, and the rise of runtimes like Node.js enabled JavaScript to power websites, servers, desktop and mobile apps, game consoles, and IoT. The ecosystem (packages, tools, frameworks) amplified that reach.
What makes JavaScript different from languages like Java or C#?Several core traits stand out: - Functions are first-class values that can be passed around and created dynamically. - Object orientation is prototype-based (classes are syntax over prototypes). - It’s single-threaded, relying on callbacks, promises, and workers for concurrency. Understanding functions, closures, objects, and prototypes is foundational.
What are JavaScript runtimes and engines, and why do they matter?A runtime is the host environment that runs your code (browsers, Node.js, Deno, Bun, etc.) and exposes platform APIs. Under the hood, each runtime uses an engine (like V8 or JavaScriptCore) that JIT-compiles JS to machine code. You usually don’t need to target a specific engine, but knowing how engines optimize code helps you write performant programs.
How does JavaScript get new features?New features are standardized through the ECMAScript process. After ES2015’s major update (modules, promises, arrow functions, etc.), new editions ship yearly. Always check which runtimes support a feature (for example, via the ECMAScript compatibility tables) and plan accordingly, especially for web apps with older browsers.
What are transpilers and polyfills, and when should I use them?- Transpilers (like Babel or the TypeScript compiler) transform modern syntax into older JS so it runs on more runtimes. - Polyfills provide missing APIs at runtime (for example, Promise in ES5 environments). Some features can’t be reliably polyfilled (for example, certain regex features), so verify target support and test in your intended runtimes.
Which web UI frameworks should I know about?React popularized writing UI with JSX and reconciling updates via a virtual DOM. Alternatives include Angular, Vue, and Svelte. Modern apps often pair these with server-side rendering (SSR) to send HTML first for faster load, then hydrate with JS. SSR-oriented frameworks (for example, Next.js, Remix, Astro) streamline this pattern.
What about server frameworks in the JavaScript ecosystem?Node.js made JS a first-class server language. Common choices include: - Express for a minimal routing/core HTTP foundation. - Full-featured frameworks like Adonis or CMS options like Keystone. - Full-stack web frameworks (Next.js, Remix, Astro) that integrate SSR, code-splitting, and great dev tooling (like HMR).
How do I build desktop and mobile apps with JavaScript?Two broad approaches: - Web view–based: Electron (desktop) and Ionic (mobile) wrap web tech (HTML/CSS/JS) in a native shell. - Native component–based: React Native renders platform-native widgets from JSX, producing apps that look and feel native on iOS and Android.
What best practices should every JavaScript developer follow?- Type checking: Use TypeScript to catch type errors early and improve IDE tooling. - Linting/formatting: Use ESLint to enforce correctness and style rules; use Prettier for consistent formatting. - Testing: Combine fast unit tests (Jest, Vitest, Mocha, Node’s built-in runner) with end-to-end tests (Playwright, Cypress) to validate real user flows.
What major challenges should a JavaScript Ninja be ready to tackle?- Performance: Avoid code bloat with tree shaking, production flags, and lazy loading; write engine-friendly code. - Collaboration at scale: Reduce cross-team friction with patterns like module federation and automate migrations with codemods. - Dependency management: Handle version conflicts, ESM vs. CommonJS issues, and mitigate supply-chain risks through careful selection, audits, and testing.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Secrets of the JavaScript Ninja, Third Edition ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Secrets of the JavaScript Ninja, Third Edition ebook for free