---
title: "Discussion on \"JavaScript Closure gotchas by reference not value\" | Hashnode"
description: "Discussion on \"JavaScript Closure gotchas by reference not value\". Closure sometimes behave undesirably, especially when you want to get by value and not by reference.\nConsider\nfunction outer() {\n    let arr=[{accumulated:-1},{accumulated:-2},{accumulated:-3}];\n    let i;\n\n    for (i=0; i<3; i++) {\n      arr[i][\"acc..."
url: "https://hashnode.com/posts/javascript-closure-gotchas-by-reference-not-value/6355f0649071d4a3e2c4107f"
---

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

Discussion

# [JavaScript Closure gotchas by reference not value](https://loganlee.hashnode.dev/javascript-closure-gotchas-by-reference-not-value?utm_source=hashnode&utm_medium=feed)

Closure sometimes behave undesirably, especially when you want to get by value and not by reference. Consider function outer() { let arr=\[{accumulated:-1},{accumulated:-2},{accumulated:-3}\]; let i; for (i=0; i<3; i++) { arr\[i\]\["acc...

Oct 24, 2022 · 1 min read · loganlee.hashnode.dev  
Read the article

-   [#by-reference](https://hashnode.com/tag/by-reference)
-   [#javascript](https://hashnode.com/tag/javascript)
-   [#closure](https://hashnode.com/tag/closure)

## Written by

[Logan Won-Ki Lee](https://hashnode.com/@loganlee)

@loganlee

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

Linux programmer

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
