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 »

Published 25 Apr 2026

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------------------)

![Image 1](https://miro.medium.com/v2/resize:fill:32:32/1*dmbNkD5D-u45r44go_cf0g.png)

# Why does this JavaScript loop log 3, 3, 3? (and what it reveals about how JS really works)

[![Image 2: Bharat Gupta](https://miro.medium.com/v2/resize:fill:32:32/0*BFNdCf6VAxZz_Lze.jpg)](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

![Image 3](https://miro.medium.com/v2/resize:fit:700/1*vAI1jrFyHZlZgsg0NLJcZQ.png)

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

![Image 4](https://miro.medium.com/v2/resize:fit:680/1*clH76yusTVPNotfN68MZ6Q.png)

If you said 0,1,2 — you're wrong. It logs 3,3,3.

Here’s why. And it reveals somethin
Read full article → ← Back to Reads