Language for web apps, APIs, and edge runtimes.
JavaScript started as a browser language and became the common API of both frontend and backend when Node.js matured. The modern ecosystem encourages shared contracts across UI and server code.
async function retryFetch(url, retries = 3) {
for (let attempt = 0; attempt <= retries; attempt++) {
try {
const res = await fetch(url);
if (!res.ok) throw new Error("temporary");
return await res.json();
} catch (error) {
if (attempt === retries) throw error;
const delay = 250 * Math.pow(2, attempt);
await new Promise(r => setTimeout(r, delay));
}
}
}