---
title: "Discussion on \"Closure and this - How are variables resolved within a function?\" | Hashnode"
description: "Discussion on \"Closure and this - How are variables resolved within a function?\". Let's start with a example of closure -\nfunction outer() {\n  // scope A\n  var myText = 'Hello'\n  return function inner() {\n    // scope B\n    console.log(myText)\n  }\n}\n\n{\n  // scope C\n  let myText = 'World'\n  let fn = outer()\n  fn();\n}\n\nHere we have ..."
url: "https://hashnode.com/posts/closure-and-this-how-are-variables-resolved-within-a-function/5f2744f6bcc1a77423c401e1"
---

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

Discussion

# [Closure and this - How are variables resolved within a function?](https://bendtherules.hashnode.dev/closure-and-this-how-are-variables-resolved-within-a-function?utm_source=hashnode&utm_medium=feed)

Let's start with a example of closure - function outer() { // scope A var myText = 'Hello' return function inner() { // scope B console.log(myText) } } { // scope C let myText = 'World' let fn = outer() fn(); } Here we have ...

Aug 2, 2020 · 7 min read · bendtherules.hashnode.dev  
Read the article

-   [#javascript](https://hashnode.com/tag/javascript)
-   [#ecmascript](https://hashnode.com/tag/ecmascript)

## Written by

[Abhas Bhattacharya](https://hashnode.com/@bendtherules)

@bendtherules · Bangalore

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

Typescripting

I like to build developer tools in my spare time. I have tried dabbling with ASTs, TypeScript compiler api, webpack plugins, react custom re

## Responses 3

Markdown supported · ⌘↵ to post

[Aquib Vadsaria](https://hashnode.com/@aqumus)

[Dec 31, 2020](https://hashnode.com/posts/closure-and-this-how-are-variables-resolved-within-a-function/5f2744f6bcc1a77423c401e1/comment/5fedeba3b2cf2458fe326a9d)

Great article to know inner working of scope resolution in JS. Small suggestion - would had been easy to understand (soak in this information) if there was some kind of visualisation (block diagram or flow chart, etc)

[Lakshya Thakur](https://hashnode.com/@lakbychance)

[Aug 3, 2020](https://hashnode.com/posts/closure-and-this-how-are-variables-resolved-within-a-function/5f2744f6bcc1a77423c401e1/comment/5f285122e7b1800ab23def5f)

Explanation - 💯. Much insightful !

[Bolaji Ayodeji](https://hashnode.com/@bolajiayodeji)

[Aug 3, 2020](https://hashnode.com/posts/closure-and-this-how-are-variables-resolved-within-a-function/5f2744f6bcc1a77423c401e1/comment/5f27fba09d473a7444cec292)

This is really amazing, thanks for sharing!
