Programming languages

JavaScript

The language of the web: runs in every browser, and on the server through Node.js, Deno and Bun.

What it is

Brendan Eich created JavaScript at Netscape in 1995. It is dynamically typed, has first-class functions, prototype-based inheritance and a single-threaded event model.

The ECMAScript standard is developed by the TC39 committee at Ecma International. A new edition ships every year (ES2015, ES2016 and so on), and proposals go through four stages before they enter the standard.

Beyond the browser, JS runs on servers (Node.js, Deno, Bun), in mobile apps (React Native) and desktop apps (Electron). Large codebases often add TypeScript on top.

Use it when

  • Any interactive frontend: no other language runs natively in the browser.
  • Full stack in one language: frontend and backend share code and types.
  • Quick prototypes, scripts, developer tools and CLIs.
  • I/O-heavy services: APIs, websockets, proxies.

Avoid it when

  • Heavy single-threaded CPU work (video encoding, scientific computing): prefer Go, Rust or C++.
  • A large team project without types: without TypeScript or strict tests, refactoring gets risky.

Key concepts

Event loop
A single-threaded model: callbacks and promises run from a queue after the current synchronous code.
Closure
A function remembers variables of its outer scope even after that scope has finished.
Prototype
Objects inherit properties from other objects through a prototype chain. class is syntactic sugar over it.
Promise / async await
An object for a future result, plus syntax that makes asynchronous code read like synchronous code.
ES modules
Standard import / export, understood by both browsers and Node.js.

Example

Async loading with a filter / map chain.

Cheat sheet

JavaScript cheat sheet
Command or codeWhat it does
const [a, ...rest] = arrArray destructuring with the rest of the items
const { id, ...props } = objObject destructuring, the rest goes to props
arr.map(x => x * 2)New array with transformed items
arr.filter(x => x > 0)Keeps items that pass the condition
arr.reduce((s, x) => s + x, 0)Folds an array into one value
obj?.a?.b ?? 'default'Safe access with a default value
const data = await (await fetch(url)).json()Request and parse JSON
Promise.all([p1, p2])Waits for all promises in parallel
{ ...a, ...b }Merge objects, the later one wins
[...new Set(arr)]Unique values of an array

How to learn it

  1. Take the JavaScript course on ShortLesson, from variables to functions and arrays.
  2. Learn the DOM and events: build a todo list without libraries.
  3. Understand closures, this and prototypes, they are the core of interviews.
  4. Learn async code: callbacks, Promises, async/await, and write a request with fetch.
  5. Meet ES modules and npm and set up a small project with Vite.
  6. Read javascript.info from the start up to the Promise chapter.
  7. Reinforce it with the JavaScript questions in the interview section of the site.
  8. Add TypeScript once plain JS feels comfortable.

Interview questions

  1. 1. What is a closure?

    A function together with a reference to the variables of the scope where it was created. That is why it still sees them after the outer function returned. Counters, private state and function factories rely on it.

  2. 2. How does the event loop work?

    Synchronous code runs on the call stack. Async callbacks go into queues, and the event loop takes tasks from them when the stack is empty. Microtasks (promises) have priority over macrotasks (setTimeout).

  3. 3. What is the difference between let, const and var?

    var is function-scoped and hoisted. let and const are block-scoped, and const forbids reassigning the binding (not mutating the object). Modern code uses const by default.

  4. 4. How does == differ from ===?

    == coerces types before comparing (0 == '0' is true), while === compares without coercion. Prefer === almost always to avoid surprising bugs.

Interview questions from the bank

Comparisons with this technology

Logos belong to their owners and are used for identification only. Icons: Simple Icons (CC0), Devicon (MIT).