<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/what-are-closures-how-does-it-work-in-javascript--whf2nh4ip" -->

---
title: What are Closures & How Does it Work in JavaScript?
description: A closure is a combination of a function bundled together with references to its surrounding state. It makes it possible for a function to have “private”...
canonical: https://daily.dev/posts/what-are-closures-how-does-it-work-in-javascript--whf2nh4ip
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: What are Closures & How Does it Work in JavaScript? | daily.dev
og:description: A closure is a combination of a function bundled together with references to its surrounding state. It makes it possible for a function to have “private”...
og:url: https://daily.dev/posts/what-are-closures-how-does-it-work-in-javascript--whf2nh4ip
og:image: https://api.daily.dev/og/posts/whF2nH4IP.png
og:image:alt: What are Closures & How Does it Work in JavaScript?
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# What are Closures & How Does it Work in JavaScript?

**[JavaScript in Plain English](https://daily.dev/sources/jsPlainEnglish)** · 3 min read · 54 upvotes · 2 comments

## Summary

A closure is a combination of a function bundled together with references to its surrounding state. It makes it possible for a function to have “private” variables. What are Closures & How Does it Work in JavaScript? A tutorial on JavaScript closures with a real-life example.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://javascript.plainenglish.io/what-is-closures-how-it-works-in-javascript-step-by-step-real-life-example-eb4a97c7120d?source=rss----4b3a1ed4f11c---4>

## Community discussion

Top comments from developers on daily.dev.

**@ahmad88** · 0 upvotes

> Cool Thanks

**@moche** · 0 upvotes

> Hey, nice one mate....

---

Tags: [#javascript](https://daily.dev/tags/javascript)

[View this post on daily.dev](https://daily.dev/posts/what-are-closures-how-does-it-work-in-javascript--whf2nh4ip)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"What are Closures & How Does it Work in JavaScript?","url":"https://daily.dev/posts/what-are-closures-how-does-it-work-in-javascript--whf2nh4ip","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/what-are-closures-how-does-it-work-in-javascript--whf2nh4ip"},"datePublished":"2022-05-09T01:53:21.222Z","dateModified":"2022-05-09T01:53:21.223Z","description":"A closure is a combination of a function bundled together with references to its surrounding state. It makes it possible for a function to have “private”...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/093ccb2cb41e0bb4c2862a64f2c540cf","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/093ccb2cb41e0bb4c2862a64f2c540cf","isAccessibleForFree":true,"articleSection":"JavaScript in Plain English","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"JavaScript in Plain English","logo":"https://media.daily.dev/image/upload/s--Dg5QTRuI--/f_auto,q_auto/v1686665538/logos/pe","url":"https://daily.dev/sources/jsPlainEnglish"},"commentCount":2,"discussionUrl":"https://daily.dev/posts/what-are-closures-how-does-it-work-in-javascript--whf2nh4ip","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":54},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":2}],"keywords":"javascript","timeRequired":"PT3M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"JavaScript in Plain English","item":"https://daily.dev/sources/jsPlainEnglish"},{"@type":"ListItem","position":3,"name":"What are Closures & How Does it Work in JavaScript?"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/what-are-closures-how-does-it-work-in-javascript--whf2nh4ip","comment":[{"@type":"Comment","text":"Cool Thanks","datePublished":"2022-05-10T06:40:24.083Z","dateModified":"2022-05-10T06:40:59.673Z","url":"https://daily.dev/posts/whF2nH4IP#c-E4Fg8WV7y","author":{"@type":"Person","name":"A D","url":"https://daily.dev/ahmad88","image":"https://lh3.googleusercontent.com/a/AATXAJx6VuUmzo0nTt2aanytiDRhciP3UnGh_hofJ0jd=s100"}},{"@type":"Comment","text":"Hey, nice one mate…","datePublished":"2022-05-09T04:12:16.952Z","url":"https://daily.dev/posts/whF2nH4IP#c-81PSgR11B","author":{"@type":"Person","name":"Moisés Miguel","url":"https://daily.dev/moche","image":"https://avatars2.githubusercontent.com/u/61609042?v=4"}}]}
```

