---
title: "Discussion on \"Understanding \"Closures in Loop\" Problem and How it is Solved in ES6\" | Hashnode"
description: "Discussion on \"Understanding \"Closures in Loop\" Problem and How it is Solved in ES6\". Understand how closures inside loops can produce unexpected results and how you can solve this problem in ES6"
url: "https://hashnode.com/posts/understanding-closures-in-loops-problem-and-how-it-is-solved-in-es6/5fe76d37999b3f21e3157a8d"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Understanding "Closures in Loop" Problem and How it is Solved in ES6](https://yousaf.hashnode.dev/understanding-closures-in-loops-problem-and-how-it-is-solved-in-es6?utm_source=hashnode&utm_medium=feed)

Understand how closures inside loops can produce unexpected results and how you can solve this problem in ES6

Dec 26, 2020 · 6 min read · yousaf.hashnode.dev  
Updated Apr 23, 2021  
Read the article

-   [#javascript](https://hashnode.com/tag/javascript)
-   [#closure](https://hashnode.com/tag/closure)
-   [#es6](https://hashnode.com/tag/es6)
-   [#es5](https://hashnode.com/tag/es5)

## Written by

[Yousaf Khan](https://hashnode.com/@yousaf)

@yousaf · Pakistan

  
[View profile](https://hashnode.com/@yousaf)

Exploring the world of software engineering

Software engineer, author of the following Javascript book: https://www.newline.co/courses/advanced-javascript-unleashed

## Responses 1

Markdown supported · ⌘↵ to post

[Samandar Boymurodov](https://hashnode.com/@samandarboymurodov)

[May 7, 2021](https://hashnode.com/posts/understanding-closures-in-loops-problem-and-how-it-is-solved-in-es6/5fe76d37999b3f21e3157a8d/comment/609579f051821218caddbe4c)

## A Great Explanation Yousaf Khan.

I read your answer to my question on **Linkedin** where you shared a link to this article. I found this article very useful.

I've understood that _var_ has a function scope which is available all over the function whereas _let_ has a block scope created unieqely for each iteration.

[Yousaf Khan](https://hashnode.com/@yousaf)

[May 8, 2021](https://hashnode.com/posts/understanding-closures-in-loops-problem-and-how-it-is-solved-in-es6/5fe76d37999b3f21e3157a8d/comment/609579f051821218caddbe4c#reply-609618831ea29f2c341dfa66)

Glad to know that you found this article useful. Thank you for the positive feedback!
