{"id":4478,"date":"2015-05-08T12:15:16","date_gmt":"2015-05-08T09:15:16","guid":{"rendered":"http:\/\/www.webcodegeeks.com\/?p=4478"},"modified":"2015-05-04T12:03:37","modified_gmt":"2015-05-04T09:03:37","slug":"javascript-tutorial-part-3-variable-scope-closures","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/javascript\/javascript-tutorial-part-3-variable-scope-closures\/","title":{"rendered":"JavaScript Tutorial \u2013 Part 3: Variable Scope and Closures"},"content":{"rendered":"<p>Previous Tutorial: <a href=\"https:\/\/www.vainolo.com\/2015\/04\/11\/javascript-tutorial-part-2-variables-functions-and-objects\/\">JavaScript Tutorial \u2013 Part 2: Variables, Functions, and Objects<\/a><\/p>\n<p>Naming is one of the hardest problems in programming. Since there are many things to decide when creating a program, programmers tend to use the same name for variables in many places. And because JavaScript is a very \u201cpromiscuous\u201d language, this can cause serious bugs that can be very hard to debug. Therefore it is very important to know what is the scope of the variables we define in our program:<\/p>\n<h3>Global Scope<\/h3>\n<p>These are variables that you declare outside functions or objects with or without the <code>var<\/code> keyword, or variables declared inside functions without the <code>var<\/code> keyword. Let\u2019s look at an example:<\/p>\n<pre class=\" brush:js\">a = 1;\r\nb = 2\r\nvar c = 3;\r\nconsole.info(\"a=\" + a + \", b=\" + b + \", c=\" + c); \/\/ prints \"a=1, b=2, c=3\"\r\nfunction foo() {\r\n    a = 6;\r\n    var b = 7\r\n    var c = 5;\r\n    d = 8;\r\n    console.info(\"a=\" + a + \", b=\" + b + \", c=\" + c+\", d=\"+d); \/\/ prints \"a=6, b=7, c=5, d=8\"\r\n}\r\nfoo();\r\nconsole.info(\"a=\" + a + \", b=\" + b + \", c=\" + c + \", d=\" + d); \/\/ prints \"a=6, b=2, c=3, d=8\"<\/pre>\n<p>We can see that setting the value of the global variable <code>a<\/code> inside function <code>foo<\/code> sets the value also outside the function. This can be prevented by using the <code>var<\/code> keyword, as done with variable <code>b<\/code>. Variable <code>c<\/code> behaves as expected as it is declared both globally and locally (a.k.a masking), therefore changes to the variable are only local. Lastly, variable <code>d<\/code> is defined inside function <code>foo<\/code> without the <code>var<\/code> declaration, therefore becomes a new global variable after the function is invoked.<\/p>\n<h3>Function Scope<\/h3>\n<p>Variables declared (with the <code>var<\/code> keyword) inside a function (or an object constructor which is also a function) are scoped to the function and all functions defined inside this function (JavaScript allows us to define functions inside functions, as we will see below). But there are some gotchas that need some investigating. Let\u2019s have an example:<\/p>\n<pre class=\" brush:js\">var a = 1;\r\nvar b = 2;\r\nvar c;\r\nconsole.info(\"a=\" + a + \", b=\" + b+\", c=\"+c); \/\/ prints \"a=1, b=2, c=undefined\"\r\nfunction foo() {\r\n    var a = 3;\r\n    var c = 4;\r\n    console.info(\"a=\" + a + \", b=\" + b + \", c=\" + c); \/\/ prints \"a=3, b=undefined, c=4\"\r\n    function bar() {\r\n        var a = 5;\r\n        c = 6;\r\n        console.info(\"a=\" + a + \", b=\" + b + \", c=\" + c); \/\/ prints \"a=5, b=7, c=6\"\r\n    }\r\n    var b = 7;\r\n    bar();\r\n    console.info(\"a=\" + a + \", b=\" + b + \", c=\" + c); \/\/ prints \"a=3, b=7, c=6\"\r\n}\r\nfoo();\r\nconsole.info(\"a=\" + a + \", b=\" + b + \", c=\" + c); \/\/ prints \"a=1, b=2, c=undefined\"<\/pre>\n<p>We first define 3 global variables to use in our example. Note that <code>c<\/code> has been defined but not yet given a value, so the output of our first print statement show it as \u201cundefined\u201d (yea, very confusing that a defined variable is called \u201cundefined\u201d instead of \u201cuninitialized\u201d\u2026 Someone is laughing at us here).<\/p>\n<p>Now comes the interesting stuff. When <code>foo<\/code> is invoked, variables <code>a<\/code> and <code>c<\/code> are redefined, masking the global variables, but when we print their value, we also get <code>b=undefined<\/code>. <a href=\"https:\/\/www.destroyallsoftware.com\/talks\/wat\">Wat?<\/a>. What is happening here is that a few lines below we defined <code>b<\/code> giving it the value <code>7<\/code>. When a function is called, the JavaScript interpreter scans for all variable definitions inside the function and creates for them a variable that is undefined, and then executes the function. Weird, and definitely something to remember.<\/p>\n<p>Moving forward, function <code>bar<\/code> is defined and executed, with <code>a<\/code> masking the local <code>a<\/code> from <code>foo<\/code>, and the assignment of <code>6<\/code> to <code>c<\/code> which changes the variable from the closing scope (<code>foo<\/code>). At the end of the example, we cab see that all variables in the global scope are unchanged, because we masked them inside the functions.<\/p>\n<h3>Closures<\/h3>\n<p>A <a href=\"http:\/\/en.wikipedia.org\/wiki\/Closure_(computer_programming)\">closure<\/a> is a way to tie a function with variables outside of its scope. The closure of a function contains all of the variables that are not defined inside the function and used by it (and are not global). Since JavaScript allows for the definition of variables inside functions, it is very easy to show how this works:<\/p>\n<pre class=\" brush:js\">function foo(x) {\r\n    var a = x;\r\n    return function () {\r\n        a = a + 5;\r\n        return a;\r\n    }\r\n}\r\nvar bar1 = foo(10);\r\nconsole.info(\"a=\" + bar1()); \/\/ prints \"a=15\"\r\nvar = foo(100);\r\nconsole.info(\"a=\" + bar2()); \/\/ prints \"a=105\"\r\nconsole.info(\"a=\" + bar1()); \/\/ prints \"a=20\"\r\nconsole.info(\"a=\" + bar2()); \/\/ prints \"a=110\"<\/pre>\n<p>We defined function <code>foo<\/code> which returns a function (cool, right?). This internal function uses the value of <code>a<\/code> defined in the enclosing scope, creating a closure. When we invoke <code>bar<\/code>, the value of <code>a<\/code> is already defined an matches the value of the parameter passed to <code>foo<\/code>. Furthermore, you can see from the output that each time <code>foo<\/code> is called, a new closure is created with a new value of <code>a<\/code>.<\/p>\n<p>Awesome.<\/p>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td><span class=\"reference\">Reference: <\/span><\/td>\n<td><a href=\"http:\/\/www.vainolo.com\/2015\/04\/19\/javascript-tutorial-part-3-variable-scope-and-closures\/\">JavaScript Tutorial \u2013 Part 3: Variable Scope and Closures<\/a> from our <a href=\"http:\/\/www.webcodegeeks.com\/wcg\/\">WCG partner<\/a> Arieh Bibliowicz at the <a href=\"http:\/\/www.vainolo.com\/\">Vainolo&#8217;s Blog<\/a> blog.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Previous Tutorial: JavaScript Tutorial \u2013 Part 2: Variables, Functions, and Objects Naming is one of the hardest problems in programming. Since there are many things to decide when creating a program, programmers tend to use the same name for variables in many places. And because JavaScript is a very \u201cpromiscuous\u201d language, this can cause serious &hellip;<\/p>\n","protected":false},"author":82,"featured_media":920,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[35],"class_list":["post-4478","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","tag-closures"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>JavaScript Tutorial \u2013 Part 3: Variable Scope and Closures - Web Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"Previous Tutorial: JavaScript Tutorial \u2013 Part 2: Variables, Functions, and Objects Naming is one of the hardest problems in programming. Since there are\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webcodegeeks.com\/javascript\/javascript-tutorial-part-3-variable-scope-closures\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JavaScript Tutorial \u2013 Part 3: Variable Scope and Closures - Web Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"Previous Tutorial: JavaScript Tutorial \u2013 Part 2: Variables, Functions, and Objects Naming is one of the hardest problems in programming. Since there are\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/javascript\/javascript-tutorial-part-3-variable-scope-closures\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webcodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2015-05-08T09:15:16+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/js-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Arieh Bibliowicz\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/vainolo\" \/>\n<meta name=\"twitter:site\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Arieh Bibliowicz\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/javascript-tutorial-part-3-variable-scope-closures\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/javascript-tutorial-part-3-variable-scope-closures\/\"},\"author\":{\"name\":\"Arieh Bibliowicz\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/79ea955d90b979ca48a0fe70849038ec\"},\"headline\":\"JavaScript Tutorial \u2013 Part 3: Variable Scope and Closures\",\"datePublished\":\"2015-05-08T09:15:16+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/javascript-tutorial-part-3-variable-scope-closures\/\"},\"wordCount\":577,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/javascript-tutorial-part-3-variable-scope-closures\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/js-logo.jpg\",\"keywords\":[\"Closures\"],\"articleSection\":[\"JavaScript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webcodegeeks.com\/javascript\/javascript-tutorial-part-3-variable-scope-closures\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/javascript-tutorial-part-3-variable-scope-closures\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/javascript\/javascript-tutorial-part-3-variable-scope-closures\/\",\"name\":\"JavaScript Tutorial \u2013 Part 3: Variable Scope and Closures - Web Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/javascript-tutorial-part-3-variable-scope-closures\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/javascript-tutorial-part-3-variable-scope-closures\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/js-logo.jpg\",\"datePublished\":\"2015-05-08T09:15:16+00:00\",\"description\":\"Previous Tutorial: JavaScript Tutorial \u2013 Part 2: Variables, Functions, and Objects Naming is one of the hardest problems in programming. Since there are\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/javascript-tutorial-part-3-variable-scope-closures\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/javascript\/javascript-tutorial-part-3-variable-scope-closures\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/javascript-tutorial-part-3-variable-scope-closures\/#primaryimage\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/js-logo.jpg\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/js-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/javascript-tutorial-part-3-variable-scope-closures\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/javascript\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"JavaScript Tutorial \u2013 Part 3: Variable Scope and Closures\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"name\":\"Web Code Geeks\",\"description\":\"Web Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webcodegeeks\",\"https:\/\/x.com\/webcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/79ea955d90b979ca48a0fe70849038ec\",\"name\":\"Arieh Bibliowicz\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e797704c245e29de3407affdab84f97eed02c8d1253d6ace5f1808426cd515e0?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e797704c245e29de3407affdab84f97eed02c8d1253d6ace5f1808426cd515e0?s=96&d=mm&r=g\",\"caption\":\"Arieh Bibliowicz\"},\"description\":\"Arieh is a longtime programmer with more than 10 years of experience in enterprise grade software projects. He has worked as server-size programmer, team leader and system architect in a mission-critical high-availability systems. Arieh is currently a Program Manager (PM) in the Microsoft ILDC R&amp;D center for the Azure Active Directory Application Proxy, and also a PhD student at the Technion where he is developing a Visual Programming Language based on the graphical language of the Object-Process Methodology, using Java and the Eclipse platform.\",\"sameAs\":[\"http:\/\/www.vainolo.com\/\",\"https:\/\/www.linkedin.com\/pub\/arieh-bibliowicz\/3\/b11\/a57\",\"https:\/\/x.com\/https:\/\/twitter.com\/vainolo\"],\"url\":\"https:\/\/www.webcodegeeks.com\/author\/arieh-bibliowicz\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JavaScript Tutorial \u2013 Part 3: Variable Scope and Closures - Web Code Geeks - 2026","description":"Previous Tutorial: JavaScript Tutorial \u2013 Part 2: Variables, Functions, and Objects Naming is one of the hardest problems in programming. Since there are","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webcodegeeks.com\/javascript\/javascript-tutorial-part-3-variable-scope-closures\/","og_locale":"en_US","og_type":"article","og_title":"JavaScript Tutorial \u2013 Part 3: Variable Scope and Closures - Web Code Geeks - 2026","og_description":"Previous Tutorial: JavaScript Tutorial \u2013 Part 2: Variables, Functions, and Objects Naming is one of the hardest problems in programming. Since there are","og_url":"https:\/\/www.webcodegeeks.com\/javascript\/javascript-tutorial-part-3-variable-scope-closures\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_published_time":"2015-05-08T09:15:16+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/js-logo.jpg","type":"image\/jpeg"}],"author":"Arieh Bibliowicz","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/vainolo","twitter_site":"@webcodegeeks","twitter_misc":{"Written by":"Arieh Bibliowicz","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/javascript\/javascript-tutorial-part-3-variable-scope-closures\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/javascript-tutorial-part-3-variable-scope-closures\/"},"author":{"name":"Arieh Bibliowicz","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/79ea955d90b979ca48a0fe70849038ec"},"headline":"JavaScript Tutorial \u2013 Part 3: Variable Scope and Closures","datePublished":"2015-05-08T09:15:16+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/javascript-tutorial-part-3-variable-scope-closures\/"},"wordCount":577,"commentCount":0,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/javascript-tutorial-part-3-variable-scope-closures\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/js-logo.jpg","keywords":["Closures"],"articleSection":["JavaScript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webcodegeeks.com\/javascript\/javascript-tutorial-part-3-variable-scope-closures\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/javascript\/javascript-tutorial-part-3-variable-scope-closures\/","url":"https:\/\/www.webcodegeeks.com\/javascript\/javascript-tutorial-part-3-variable-scope-closures\/","name":"JavaScript Tutorial \u2013 Part 3: Variable Scope and Closures - Web Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/javascript-tutorial-part-3-variable-scope-closures\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/javascript-tutorial-part-3-variable-scope-closures\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/js-logo.jpg","datePublished":"2015-05-08T09:15:16+00:00","description":"Previous Tutorial: JavaScript Tutorial \u2013 Part 2: Variables, Functions, and Objects Naming is one of the hardest problems in programming. Since there are","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/javascript-tutorial-part-3-variable-scope-closures\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/javascript\/javascript-tutorial-part-3-variable-scope-closures\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/javascript\/javascript-tutorial-part-3-variable-scope-closures\/#primaryimage","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/js-logo.jpg","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/js-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.webcodegeeks.com\/javascript\/javascript-tutorial-part-3-variable-scope-closures\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"JavaScript","item":"https:\/\/www.webcodegeeks.com\/category\/javascript\/"},{"@type":"ListItem","position":3,"name":"JavaScript Tutorial \u2013 Part 3: Variable Scope and Closures"}]},{"@type":"WebSite","@id":"https:\/\/www.webcodegeeks.com\/#website","url":"https:\/\/www.webcodegeeks.com\/","name":"Web Code Geeks","description":"Web Developers Resource Center","publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.webcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webcodegeeks","https:\/\/x.com\/webcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/79ea955d90b979ca48a0fe70849038ec","name":"Arieh Bibliowicz","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e797704c245e29de3407affdab84f97eed02c8d1253d6ace5f1808426cd515e0?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e797704c245e29de3407affdab84f97eed02c8d1253d6ace5f1808426cd515e0?s=96&d=mm&r=g","caption":"Arieh Bibliowicz"},"description":"Arieh is a longtime programmer with more than 10 years of experience in enterprise grade software projects. He has worked as server-size programmer, team leader and system architect in a mission-critical high-availability systems. Arieh is currently a Program Manager (PM) in the Microsoft ILDC R&amp;D center for the Azure Active Directory Application Proxy, and also a PhD student at the Technion where he is developing a Visual Programming Language based on the graphical language of the Object-Process Methodology, using Java and the Eclipse platform.","sameAs":["http:\/\/www.vainolo.com\/","https:\/\/www.linkedin.com\/pub\/arieh-bibliowicz\/3\/b11\/a57","https:\/\/x.com\/https:\/\/twitter.com\/vainolo"],"url":"https:\/\/www.webcodegeeks.com\/author\/arieh-bibliowicz\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/4478","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/users\/82"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/comments?post=4478"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/4478\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media\/920"}],"wp:attachment":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media?parent=4478"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=4478"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=4478"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}