---
title: "Discussion on \"JavaScript how to create persistent variable\" | Hashnode"
description: "Discussion on \"JavaScript how to create persistent variable\". First method is to return a function inside parent function. Note that the inner function has access to private property of parent.\nconst incr=(function(v) {\n    return function() {\n        return ++v;\n  }\n})(100);\n\nconsole.log(incr());  //101\nconsol..."
url: "https://hashnode.com/posts/javascript-how-to-create-persistent-variable/6355cb8a2baa7a5b6036c5d0"
---

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

Discussion

# [JavaScript how to create persistent variable](https://loganlee.hashnode.dev/javascript-how-to-create-persistent-variable?utm_source=hashnode&utm_medium=feed)

First method is to return a function inside parent function. Note that the inner function has access to private property of parent. const incr=(function(v) { return function() { return ++v; } })(100); console.log(incr()); //101 consol...

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

-   [#static-variable](https://hashnode.com/tag/static-variable)
-   [#persistent](https://hashnode.com/tag/persistent)
-   [#javascript](https://hashnode.com/tag/javascript)

## 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.
