Skip to content
tezvyn:

TypeScript & Web APIs

TypeScript, browser APIs, WebAssembly, PWAs

74 bites

Test yourself: Top 30 easy TypeScript & Web APIs interview questionsMultiple choice, with the correct answer and why it is correct on every question. Free, no sign-in.

Easy everything in TypeScript & Web APIs, page 3

easy2 min read

Triple-Slash Directives: Compiler Hints in Comments

Triple-slash directives are compiler instructions inside comments, telling TypeScript about file dependencies. They're mostly seen in older projects or for global types, as modern import statements are preferred.

easy2 min read

TypeScript: Type-Only Imports and Exports

Use import type to tell the compiler an import is only for type-checking and should be erased from the final JavaScript. This prevents tools like Babel from generating unwanted runtime code when compiling files in isolation.

easy2 min read

TypeScript's `declare`: A Promise to the Compiler

declare promises the TypeScript compiler a value exists, even if it can't see the source. This lets you use untyped JavaScript libraries or browser APIs without errors.

DefinitelyTyped: Type Definitions for JavaScript Libraries
easy1 min read

DefinitelyTyped: Type Definitions for JavaScript Libraries

@types packages from DefinitelyTyped are instruction manuals for JavaScript libraries, letting TypeScript understand their shapes. You install them for JS libs that lack their own types, enabling autocompletion.

easy2 min read

Declaration Files: How TypeScript Knows Your Library's Shape

A .d.ts file is a type-only blueprint for existing JavaScript code, describing its shape without any implementation. This is how TypeScript provides type-checking for third-party libraries or browser APIs. The footgun is adding logic to them; it's ignored.

Canvas drawImage: Projecting Pixels onto a Canvas
easy2 min read

Canvas drawImage: Projecting Pixels onto a Canvas

drawImage is a versatile projector for your canvas, letting you place, scale, and even slice images before drawing them. It's used for rendering game sprites from a sprite sheet, displaying video frames, or compositing images.

Managing Canvas State with save() and restore()
easy2 min read

Managing Canvas State with save() and restore()

Think of save() and restore() as checkpoints for your canvas. save() pushes the current drawing state (styles, transforms) onto a stack, and restore() pops it back off. Use this to temporarily apply a transformation to just one element.

Requesting Camera and Mic Access with getUserMedia
easy2 min read

Requesting Camera and Mic Access with getUserMedia

getUserMedia asks for camera/mic access in the browser. It's used for video chats or photo booths and returns a Promise with the media stream. Footgun: The promise can hang forever if the user ignores the prompt, so your app must handle that state.

Canvas 2D Context: The API for Drawing on the Web
easy2 min read

Canvas 2D Context: The API for Drawing on the Web

The Canvas 2D Context is your digital paintbrush and ruler for drawing on a web page. You get this object from a <canvas> element to draw shapes, text, and images for data visualizations or simple games. The key footgun: it's a state machine.

HTMLMediaElement: The Remote Control for Browser Media
easy2 min read

HTMLMediaElement: The Remote Control for Browser Media

HTMLMediaElement is the shared "remote control" API for <audio> and <video> tags, letting you programmatically play, pause, and seek. Use it for custom players or syncing animations. Footgun: Browsers often block autoplay, so never assume it will work.

Service Worker Registration: Claiming Your Control Scope
easy2 min read

Service Worker Registration: Claiming Your Control Scope

Registering a service worker is like assigning a security guard (your script) to a specific area (the scope) of your site for offline support. The footgun: by default, a worker can only control its own directory, not the whole site.

Web Workers: Keep Your UI Responsive During Heavy Tasks
easy2 min read

Web Workers: Keep Your UI Responsive During Heavy Tasks

A Web Worker is like a background helper, running heavy JavaScript tasks in a separate thread so your UI never freezes. Use it for complex calculations or data fetching. The main footgun: workers cannot directly manipulate the DOM.

The `popstate` Event: Handling Browser History Navigation
easy2 min read

The `popstate` Event: Handling Browser History Navigation

The popstate event lets your app react to browser back/forward clicks. It's key for SPAs to update views without a full reload. The main footgun: the event fires before the document is fully updated, so your handler might read a stale DOM.

Manipulate Browser History with pushState and replaceState
easy2 min read

Manipulate Browser History with pushState and replaceState

Make a single-page app feel like a multi-page site. pushState changes the URL without a full page reload, creating a new browser history entry. This is essential for SPAs to enable shareable links and a working back button.

Storing Objects in Web Storage: The JSON Step
easy2 min read

Storing Objects in Web Storage: The JSON Step

Web Storage only stores strings. To save complex data like objects, you must first serialize them with JSON.stringify(). This is essential for persisting user settings or session info.

sessionStorage: Tab-Specific Browser Memory
easy2 min read

sessionStorage: Tab-Specific Browser Memory

sessionStorage is temporary browser memory isolated to a single tab. Use it to save state within a single user workflow, like form data. The footgun: unlike localStorage, this data is *not* shared between tabs, even for the same site.

localStorage: Your Browser's Persistent Key-Value Store
easy2 min read

localStorage: Your Browser's Persistent Key-Value Store

localStorage is a simple dictionary saved in the browser that persists after the tab closes. Use it to save user settings like a theme. The footgun: all values are strings, so numbers and booleans need manual conversion, like parsing 'true' back to a boolean.

easy2 min read

Indexed Access Types: Look Up a Property's Type

Indexed access types let you look up a property's type on another type, like Person['age'] yielding number. Use them to create new types from existing ones, like getting an array element's type with MyArray[number].

Fetch API Errors: Why a 404 is a 'Success'
easy2 min read

Fetch API Errors: Why a 404 is a 'Success'

A fetch() call only fails on network errors, not on HTTP errors like 404. You must check the response.ok property to see if the request was successful. The footgun is assuming a catch block will handle a 404; it won't.

Configuring Fetch Requests with `RequestInit`
easy1 min read

Configuring Fetch Requests with `RequestInit`

RequestInit is the options object that customizes a fetch call beyond a simple GET. Use it to specify the HTTP method, send a request body, set headers, and control caching. A common footgun is sending a JSON body without setting the Content-Type header.

We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.

See open roles