Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Awaiting inside JavaScript template strings
// https://dev.to/noseratio/await-inside-javascript-template-strings-3kbj
//
// save this as .mjs or as "node --input-type=module < file.js"
const delay = (ms, result) => new Promise(r => setTimeout(r, ms, result));
const interpolated = `Hello, ${await delay(1000, "World!")} Is this sync or async?`;
console.log(interpolated)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment