Why does this JavaScript loop log 3, 3, 3? (and what it reveals about how JS really works)
📰 Medium · JavaScript
A no-fluff guide to var, let, and const, the basics you think you know, and the weird parts that will bite you in an interview. Continue reading on Medium »
Full Article
Title: Why does this JavaScript loop log 3, 3, 3? (and what it reveals about how JS really works)
URL Source: https://medium.com/@guptabharat297/why-does-this-javascript-loop-log-3-3-3-and-what-it-reveals-about-how-js-really-works-d5eaa7d2922d?source=rss------javascript-5
Published Time: 2026-04-25T21:01:31Z
Markdown Content:
# Why does this JavaScript loop log 3, 3, 3? (and what it reveals about how JS really works) | by Bharat Gupta | 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%40guptabharat297%2Fwhy-does-this-javascript-loop-log-3-3-3-and-what-it-reveals-about-how-js-really-works-d5eaa7d2922d&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%40guptabharat297%2Fwhy-does-this-javascript-loop-log-3-3-3-and-what-it-reveals-about-how-js-really-works-d5eaa7d2922d&source=post_page---top_nav_layout_nav-----------------------global_nav------------------)

# Why does this JavaScript loop log 3, 3, 3? (and what it reveals about how JS really works)
[](https://medium.com/@guptabharat297?source=post_page---byline--d5eaa7d2922d---------------------------------------)
[Bharat Gupta](https://medium.com/@guptabharat297?source=post_page---byline--d5eaa7d2922d---------------------------------------)
Follow
3 min read
·
Just now
[](https://medium.com/m/signin?actionUrl=https%3A%2F%2Fmedium.com%2F_%2Fvote%2Fp%2Fd5eaa7d2922d&operation=register&redirect=https%3A%2F%2Fmedium.com%2F%40guptabharat297%2Fwhy-does-this-javascript-loop-log-3-3-3-and-what-it-reveals-about-how-js-really-works-d5eaa7d2922d&user=Bharat+Gupta&userId=c42cc5bcbd4f&source=---header_actions--d5eaa7d2922d---------------------clap_footer------------------)
[](https://medium.com/m/signin?actionUrl=https%3A%2F%2Fmedium.com%2F_%2Fbookmark%2Fp%2Fd5eaa7d2922d&operation=register&redirect=https%3A%2F%2Fmedium.com%2F%40guptabharat297%2Fwhy-does-this-javascript-loop-log-3-3-3-and-what-it-reveals-about-how-js-really-works-d5eaa7d2922d&source=---header_actions--d5eaa7d2922d---------------------bookmark_footer------------------)
[Listen](https://medium.com/m/signin?actionUrl=https%3A%2F%2Fmedium.com%2Fplans%3Fdimension%3Dpost_audio_button%26postId%3Dd5eaa7d2922d&operation=register&redirect=https%3A%2F%2Fmedium.com%2F%40guptabharat297%2Fwhy-does-this-javascript-loop-log-3-3-3-and-what-it-reveals-about-how-js-really-works-d5eaa7d2922d&source=---header_actions--d5eaa7d2922d---------------------post_audio_button------------------)
Share
_A no-fluff guide to var, let, and const, the basics you think you know, and the weird parts that will bite you in an interview._
Press enter or click to view image in full size

Before I explain anything, what do you think about this code and what it will log?

If you said 0,1,2 — you're wrong. It logs 3,3,3.
Here’s why. And it reveals somethin
URL Source: https://medium.com/@guptabharat297/why-does-this-javascript-loop-log-3-3-3-and-what-it-reveals-about-how-js-really-works-d5eaa7d2922d?source=rss------javascript-5
Published Time: 2026-04-25T21:01:31Z
Markdown Content:
# Why does this JavaScript loop log 3, 3, 3? (and what it reveals about how JS really works) | by Bharat Gupta | 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%40guptabharat297%2Fwhy-does-this-javascript-loop-log-3-3-3-and-what-it-reveals-about-how-js-really-works-d5eaa7d2922d&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%40guptabharat297%2Fwhy-does-this-javascript-loop-log-3-3-3-and-what-it-reveals-about-how-js-really-works-d5eaa7d2922d&source=post_page---top_nav_layout_nav-----------------------global_nav------------------)

# Why does this JavaScript loop log 3, 3, 3? (and what it reveals about how JS really works)
[](https://medium.com/@guptabharat297?source=post_page---byline--d5eaa7d2922d---------------------------------------)
[Bharat Gupta](https://medium.com/@guptabharat297?source=post_page---byline--d5eaa7d2922d---------------------------------------)
Follow
3 min read
·
Just now
[](https://medium.com/m/signin?actionUrl=https%3A%2F%2Fmedium.com%2F_%2Fvote%2Fp%2Fd5eaa7d2922d&operation=register&redirect=https%3A%2F%2Fmedium.com%2F%40guptabharat297%2Fwhy-does-this-javascript-loop-log-3-3-3-and-what-it-reveals-about-how-js-really-works-d5eaa7d2922d&user=Bharat+Gupta&userId=c42cc5bcbd4f&source=---header_actions--d5eaa7d2922d---------------------clap_footer------------------)
[](https://medium.com/m/signin?actionUrl=https%3A%2F%2Fmedium.com%2F_%2Fbookmark%2Fp%2Fd5eaa7d2922d&operation=register&redirect=https%3A%2F%2Fmedium.com%2F%40guptabharat297%2Fwhy-does-this-javascript-loop-log-3-3-3-and-what-it-reveals-about-how-js-really-works-d5eaa7d2922d&source=---header_actions--d5eaa7d2922d---------------------bookmark_footer------------------)
[Listen](https://medium.com/m/signin?actionUrl=https%3A%2F%2Fmedium.com%2Fplans%3Fdimension%3Dpost_audio_button%26postId%3Dd5eaa7d2922d&operation=register&redirect=https%3A%2F%2Fmedium.com%2F%40guptabharat297%2Fwhy-does-this-javascript-loop-log-3-3-3-and-what-it-reveals-about-how-js-really-works-d5eaa7d2922d&source=---header_actions--d5eaa7d2922d---------------------post_audio_button------------------)
Share
_A no-fluff guide to var, let, and const, the basics you think you know, and the weird parts that will bite you in an interview._
Press enter or click to view image in full size

Before I explain anything, what do you think about this code and what it will log?

If you said 0,1,2 — you're wrong. It logs 3,3,3.
Here’s why. And it reveals somethin
DeepCamp AI