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.
classis 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
Cheat sheet
| Command or code | What it does |
|---|---|
const [a, ...rest] = arr | Array destructuring with the rest of the items |
const { id, ...props } = obj | Object 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
- Take the JavaScript course on ShortLesson, from variables to functions and arrays.
- Learn the DOM and events: build a todo list without libraries.
- Understand closures, this and prototypes, they are the core of interviews.
- Learn async code: callbacks, Promises, async/await, and write a request with fetch.
- Meet ES modules and npm and set up a small project with Vite.
- Read javascript.info from the start up to the Promise chapter.
- Reinforce it with the JavaScript questions in the interview section of the site.
- Add TypeScript once plain JS feels comfortable.
Interview questions
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. 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. What is the difference between let, const and var?
varis function-scoped and hoisted.letandconstare block-scoped, andconstforbids reassigning the binding (not mutating the object). Modern code usesconstby default.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
- How does an object differ from an array in JavaScript?JuniorJavaScript
- Given
const a = { n: 1 }; const b = a; b.n = 2;, what doesconsole.log(a.n)print and why?JuniorJavaScript - What is a callback in simple words? Give an example.JuniorJavaScript
- The code prints
A, then schedulessetTimeout(() => console.log('B'), 0), then printsC. In what order do the letters appear and why?JuniorJavaScript - An async function
getUserreturns the string'Olya'. What doesconsole.log(getUser())print in Node.js and how do you get the string itself?JuniorJavaScript - What do
typeof nullandtypeof NaNreturn? How doisNaNandNumber.isNaNdiffer, and how do you filter out an invalid number from a query parameter?JuniorJavaScript - A function has
console.log(x)and below itlet x = 'inner', while the outerxequals'outer'. What does the call print and why is the outer value not used?MiddleJavaScript - A
for (var i = 0; i < 3; i++)loop schedules asetTimeoutthat printsi. What does it print, and what does a similar loop withletin the header print? Why does aletdeclared outside the loop behave likevar?MiddleJavaScript
Comparisons with this technology
Related technologies
Logos belong to their owners and are used for identification only. Icons: Simple Icons (CC0), Devicon (MIT).