Why return Doesn’t Work in setTimeout: The JavaScript Async Model Explained
📰 Medium · JavaScript
(And What You Should Do Instead) Continue reading on Medium »
Full Article
Title: Why return Doesn’t Work in setTimeout: The JavaScript Async Model Explained
URL Source: https://medium.com/@akanksha.mohanty.sg/why-return-doesnt-work-in-settimeout-the-javascript-async-model-explained-080c26b56639?source=rss------javascript-5
Published Time: 2026-04-14T17:03:59Z
Markdown Content:
# Why return Doesn’t Work in setTimeout: The JavaScript Async Model Explained | by Akanksha Mohanty | Apr, 2026 | Medium
[Sitemap](https://medium.com/sitemap/sitemap.xml)
[Open in app](https://play.google.com/store/apps/details?id=com.medium.reader&referrer=utm_source%3DmobileNavBar&source=post_page---top_nav_layout_nav-----------------------------------------)
Sign up
[Sign in](https://medium.com/m/signin?operation=login&redirect=https%3A%2F%2Fmedium.com%2F%40akanksha.mohanty.sg%2Fwhy-return-doesnt-work-in-settimeout-the-javascript-async-model-explained-080c26b56639&source=post_page---top_nav_layout_nav-----------------------global_nav------------------)
[](https://medium.com/?source=post_page---top_nav_layout_nav-----------------------------------------)
Get app
[Write](https://medium.com/m/signin?operation=register&redirect=https%3A%2F%2Fmedium.com%2Fnew-story&source=---top_nav_layout_nav-----------------------new_post_topnav------------------)
[Search](https://medium.com/search?source=post_page---top_nav_layout_nav-----------------------------------------)
Sign up
[Sign in](https://medium.com/m/signin?operation=login&redirect=https%3A%2F%2Fmedium.com%2F%40akanksha.mohanty.sg%2Fwhy-return-doesnt-work-in-settimeout-the-javascript-async-model-explained-080c26b56639&source=post_page---top_nav_layout_nav-----------------------global_nav------------------)

# Why `return` Doesn’t Work in `setTimeout`: The JavaScript Async Model Explained
[](https://medium.com/@akanksha.mohanty.sg?source=post_page---byline--080c26b56639---------------------------------------)
[Akanksha Mohanty](https://medium.com/@akanksha.mohanty.sg?source=post_page---byline--080c26b56639---------------------------------------)
Follow
3 min read
·
1 hour ago
[](https://medium.com/m/signin?actionUrl=https%3A%2F%2Fmedium.com%2F_%2Fvote%2Fp%2F080c26b56639&operation=register&redirect=https%3A%2F%2Fmedium.com%2F%40akanksha.mohanty.sg%2Fwhy-return-doesnt-work-in-settimeout-the-javascript-async-model-explained-080c26b56639&user=Akanksha+Mohanty&userId=2de3deccf6de&source=---header_actions--080c26b56639---------------------clap_footer------------------)
1
[](https://medium.com/m/signin?actionUrl=https%3A%2F%2Fmedium.com%2F_%2Fbookmark%2Fp%2F080c26b56639&operation=register&redirect=https%3A%2F%2Fmedium.com%2F%40akanksha.mohanty.sg%2Fwhy-return-doesnt-work-in-settimeout-the-javascript-async-model-explained-080c26b56639&source=---header_actions--080c26b56639---------------------bookmark_footer------------------)
[Listen](https://medium.com/m/signin?actionUrl=https%3A%2F%2Fmedium.com%2Fplans%3Fdimension%3Dpost_audio_button%26postId%3D080c26b56639&operation=register&redirect=https%3A%2F%2Fmedium.com%2F%40akanksha.mohanty.sg%2Fwhy-return-doesnt-work-in-settimeout-the-javascript-async-model-explained-080c26b56639&source=---header_actions--080c26b56639---------------------post_audio_button------------------)
Share
(And What You Should Do Instead)
Press enter or click to view image in full size

The `setTimeout` Trap That Confuses Every JavaScript Developer
If you’ve ever written JavaScript like this:
function asyncFn(msg) {
setTimeout(() => {
return `Subscribe to ${msg}`;
}, 1000);
}
const result = asyncFn("YouTube");
console.log(result);
…and stared in disbelief at:
undefined
You’re not alone.
This confusion is **one of the most common JavaScript pitfalls**, especially for de
URL Source: https://medium.com/@akanksha.mohanty.sg/why-return-doesnt-work-in-settimeout-the-javascript-async-model-explained-080c26b56639?source=rss------javascript-5
Published Time: 2026-04-14T17:03:59Z
Markdown Content:
# Why return Doesn’t Work in setTimeout: The JavaScript Async Model Explained | by Akanksha Mohanty | Apr, 2026 | Medium
[Sitemap](https://medium.com/sitemap/sitemap.xml)
[Open in app](https://play.google.com/store/apps/details?id=com.medium.reader&referrer=utm_source%3DmobileNavBar&source=post_page---top_nav_layout_nav-----------------------------------------)
Sign up
[Sign in](https://medium.com/m/signin?operation=login&redirect=https%3A%2F%2Fmedium.com%2F%40akanksha.mohanty.sg%2Fwhy-return-doesnt-work-in-settimeout-the-javascript-async-model-explained-080c26b56639&source=post_page---top_nav_layout_nav-----------------------global_nav------------------)
[](https://medium.com/?source=post_page---top_nav_layout_nav-----------------------------------------)
Get app
[Write](https://medium.com/m/signin?operation=register&redirect=https%3A%2F%2Fmedium.com%2Fnew-story&source=---top_nav_layout_nav-----------------------new_post_topnav------------------)
[Search](https://medium.com/search?source=post_page---top_nav_layout_nav-----------------------------------------)
Sign up
[Sign in](https://medium.com/m/signin?operation=login&redirect=https%3A%2F%2Fmedium.com%2F%40akanksha.mohanty.sg%2Fwhy-return-doesnt-work-in-settimeout-the-javascript-async-model-explained-080c26b56639&source=post_page---top_nav_layout_nav-----------------------global_nav------------------)

# Why `return` Doesn’t Work in `setTimeout`: The JavaScript Async Model Explained
[](https://medium.com/@akanksha.mohanty.sg?source=post_page---byline--080c26b56639---------------------------------------)
[Akanksha Mohanty](https://medium.com/@akanksha.mohanty.sg?source=post_page---byline--080c26b56639---------------------------------------)
Follow
3 min read
·
1 hour ago
[](https://medium.com/m/signin?actionUrl=https%3A%2F%2Fmedium.com%2F_%2Fvote%2Fp%2F080c26b56639&operation=register&redirect=https%3A%2F%2Fmedium.com%2F%40akanksha.mohanty.sg%2Fwhy-return-doesnt-work-in-settimeout-the-javascript-async-model-explained-080c26b56639&user=Akanksha+Mohanty&userId=2de3deccf6de&source=---header_actions--080c26b56639---------------------clap_footer------------------)
1
[](https://medium.com/m/signin?actionUrl=https%3A%2F%2Fmedium.com%2F_%2Fbookmark%2Fp%2F080c26b56639&operation=register&redirect=https%3A%2F%2Fmedium.com%2F%40akanksha.mohanty.sg%2Fwhy-return-doesnt-work-in-settimeout-the-javascript-async-model-explained-080c26b56639&source=---header_actions--080c26b56639---------------------bookmark_footer------------------)
[Listen](https://medium.com/m/signin?actionUrl=https%3A%2F%2Fmedium.com%2Fplans%3Fdimension%3Dpost_audio_button%26postId%3D080c26b56639&operation=register&redirect=https%3A%2F%2Fmedium.com%2F%40akanksha.mohanty.sg%2Fwhy-return-doesnt-work-in-settimeout-the-javascript-async-model-explained-080c26b56639&source=---header_actions--080c26b56639---------------------post_audio_button------------------)
Share
(And What You Should Do Instead)
Press enter or click to view image in full size

The `setTimeout` Trap That Confuses Every JavaScript Developer
If you’ve ever written JavaScript like this:
function asyncFn(msg) {
setTimeout(() => {
return `Subscribe to ${msg}`;
}, 1000);
}
const result = asyncFn("YouTube");
console.log(result);
…and stared in disbelief at:
undefined
You’re not alone.
This confusion is **one of the most common JavaScript pitfalls**, especially for de
DeepCamp AI