---
title: "Discussion on \"You (may not) Know JS\" | Hashnode"
description: "Discussion on \"You (may not) Know JS\". A wild Closure appeared and it's super effective"
url: "https://hashnode.com/posts/you-may-not-know-js/60762cecab0af52a0fead63a"
---

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

Discussion

# [You (may not) Know JS](https://dsmorais.hashnode.dev/you-may-not-know-js?utm_source=hashnode&utm_medium=feed)

A wild Closure appeared and it's super effective

Apr 13, 2021 · 7 min read · dsmorais.hashnode.dev  
Updated Apr 15, 2021  
Read the article

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

## Written by

[David Morais](https://hashnode.com/@DavidMorais)

@DavidMorais

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

Fullstack Developer

Got a languages degree, became developer 🚀❤ Developing Epoch Rift on my free time

## Responses 4

Markdown supported · ⌘↵ to post

[Golden Azubuike](https://hashnode.com/@gforge)

[Apr 15, 2021](https://hashnode.com/posts/you-may-not-know-js/60762cecab0af52a0fead63a/comment/607815a5a3407a32d70430a1)

Educative and cool

[sascha sascha](https://hashnode.com/@Sascha10k)

[Apr 14, 2021](https://hashnode.com/posts/you-may-not-know-js/60762cecab0af52a0fead63a/comment/6076e52ca3407a32d7041761)

Nice article, good visualizations.

But your explanation of closures is not correct and it happens a lot. You are describing lexical scoping as far as I remember.

A closure "closes" the function.

```
function a() {
 let me = 0;
 function b(){
  me = 1;
 }

 return b;
}

let fA = a(); // function is still "in the memory"
fA(); // now it is getting removed "from the memory"
```

The final execution of b() by calling fA() closes a(). So the name isn't even that bad.

[Tony B](https://hashnode.com/@octree)

[Apr 14, 2021](https://hashnode.com/posts/you-may-not-know-js/60762cecab0af52a0fead63a/comment/6076e52ca3407a32d7041761#reply-6076fa5aa3407a32d7041afb)

[David Morais](https://hashnode.com/@DavidMorais)

I don't think you are correct about your example being a closure - even according to MDN's explanation.

"a function bundled together (enclosed) with references to its surrounding state"

You took the bit about surrounding state, but ignored the bit about a function being bundled together/enclosed. Your example is just looking at global state - that isn't bundled, that is open to everyone to mess with. :)

I would update it anyway for teaching purposes, as the rest of your article is excellent IMHO.

[sascha sascha](https://hashnode.com/@Sascha10k)

[Apr 14, 2021](https://hashnode.com/posts/you-may-not-know-js/60762cecab0af52a0fead63a/comment/6076e52ca3407a32d7041761#reply-6076ffc24155da32fc83aa1b)

[David Morais](https://hashnode.com/@DavidMorais)

yes it is still there I think therefore the quotes. as [Tony B](https://hashnode.com/@octree) said I would change it because the word closure is about the enclosed state and not purely about scope and your article is very good.

[David Morais](https://hashnode.com/@DavidMorais)

[Apr 14, 2021](https://hashnode.com/posts/you-may-not-know-js/60762cecab0af52a0fead63a/comment/6076e52ca3407a32d7041761#reply-607714c94155da32fc83acf6)

I'll update it later today, but I'm still in doubt wether this implicit global scope doesn't count as an enclosure. [Tony B](https://hashnode.com/@octree) thanks for the read and the feedback 🤘🤘

Thank you both

EDIT: Updated both snippets.

[Manthankumar Satani](https://hashnode.com/@itsmnthn)

[Apr 14, 2021](https://hashnode.com/posts/you-may-not-know-js/60762cecab0af52a0fead63a/comment/6076d15c4155da32fc83a279)

Great compilations with specific comments. I learned few things, thanks.

[David Morais](https://hashnode.com/@DavidMorais)

[Apr 14, 2021](https://hashnode.com/posts/you-may-not-know-js/60762cecab0af52a0fead63a/comment/6076d15c4155da32fc83a279#reply-6076e93d4155da32fc83a613)

Thanks 👋

[Karol](https://hashnode.com/@Szarlus)

[Apr 14, 2021](https://hashnode.com/posts/you-may-not-know-js/60762cecab0af52a0fead63a/comment/6076a2daa3407a32d7040f21)

Hi! On the screenshot under the nullish operator you've got it wrong.

```
null ?? "foo" =/= null
```

[David Morais](https://hashnode.com/@DavidMorais)

[Apr 14, 2021](https://hashnode.com/posts/you-may-not-know-js/60762cecab0af52a0fead63a/comment/6076a2daa3407a32d7040f21#reply-6076a70fa3407a32d7040fbb)

Hey, thanks for reading 👋 You are absolutely right, I need to change that.

Thanks for catching that.

EDIT: Updated 🚀

[Karol](https://hashnode.com/@Szarlus)

[Apr 14, 2021](https://hashnode.com/posts/you-may-not-know-js/60762cecab0af52a0fead63a/comment/6076a2daa3407a32d7040f21#reply-6076b9dca3407a32d7041214)

[David Morais](https://hashnode.com/@DavidMorais) Great, thanks! Sorry that my first comment is pointing out mistakes instead of congratulating you on a nice article, which it obviously is ;) Thanks for you work and input :D
