{"id":850,"date":"2015-11-20T14:52:13","date_gmt":"2015-11-20T09:22:13","guid":{"rendered":"http:\/\/www.prasadk.com\/my-press\/?p=850"},"modified":"2017-08-25T22:38:47","modified_gmt":"2017-08-25T17:08:47","slug":"understanding-the-javascript-closures","status":"publish","type":"post","link":"https:\/\/www.prasadk.com\/my-press\/understanding-the-javascript-closures\/","title":{"rendered":"Understanding the JavaScript Closures"},"content":{"rendered":"<p><h2>Understanding the JavaScript Closures<\/h2>\n<\/p>\n<h3><strong>What is a closure?<\/strong><\/h3>\n<blockquote><p>A closure is an inner function that has access to the outer\/enclosing function\u2019s variables scope chain.<br \/>\nClosure has three scope chains i.e.,<br \/>\n1) It has access to its own scope (variables defined between its curly brackets)<br \/>\n2) It has access to the outer function\u2019s variables, and<br \/>\n3) It has access to the global variables.<\/p><\/blockquote>\n<p>The inner function has access not only to the outer function\u2019s variables, but also to the outer function\u2019s parameters.<\/p>\n<p>Note that the inner function cannot call the outer function\u2019s <em>arguments\u00a0<\/em>object; however, even though it can call the outer function\u2019s param&#8217;s directly.<\/p>\n<p>In simpler way to say what is closure? If you create\u00a0a function inside \/ within another function\u00a0its called as closure \/ private function.<\/p>\n<p><img loading=\"lazy\" src=\"http:\/\/www.prasadk.com\/my-press\/wp-content\/uploads\/2015\/11\/closureOBJ.png\" alt=\"Understanding the JavaScript Closures\" width=\"1011\" height=\"315\" class=\"aligncenter size-full wp-image-970\" srcset=\"https:\/\/www.prasadk.com\/my-press\/wp-content\/uploads\/2015\/11\/closureOBJ.png 1011w, https:\/\/www.prasadk.com\/my-press\/wp-content\/uploads\/2015\/11\/closureOBJ-300x93.png 300w, https:\/\/www.prasadk.com\/my-press\/wp-content\/uploads\/2015\/11\/closureOBJ-768x239.png 768w, https:\/\/www.prasadk.com\/my-press\/wp-content\/uploads\/2015\/11\/closureOBJ-690x215.png 690w, https:\/\/www.prasadk.com\/my-press\/wp-content\/uploads\/2015\/11\/closureOBJ-980x305.png 980w\" sizes=\"(max-width: 1011px) 100vw, 1011px\" \/><\/p>\n<h4>An Example of Closures in JavaScript:<\/h4>\n<p>&nbsp;<\/p>\n<p>Will come up with next article on this with more details of closures and some more example&#8217;s &amp; Closures\u2019 Rules and Side Effects, usage and so on&#8230;.<br \/>\n&nbsp;<br \/>\nYou can find more even in W3C about closures:<br \/>\nURL :\u00a0<a href=\"http:\/\/www.w3schools.com\/js\/js_function_closures.asp\" target=\"_blank\">http:\/\/www.w3schools.com\/js\/js_function_closures.asp<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Understanding the JavaScript Closures What is a closure? A closure is an inner function that has access to the outer\/enclosing function\u2019s variables scope chain. Closure [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0},"categories":[7,11,6],"tags":[],"_links":{"self":[{"href":"https:\/\/www.prasadk.com\/my-press\/wp-json\/wp\/v2\/posts\/850"}],"collection":[{"href":"https:\/\/www.prasadk.com\/my-press\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.prasadk.com\/my-press\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.prasadk.com\/my-press\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.prasadk.com\/my-press\/wp-json\/wp\/v2\/comments?post=850"}],"version-history":[{"count":14,"href":"https:\/\/www.prasadk.com\/my-press\/wp-json\/wp\/v2\/posts\/850\/revisions"}],"predecessor-version":[{"id":973,"href":"https:\/\/www.prasadk.com\/my-press\/wp-json\/wp\/v2\/posts\/850\/revisions\/973"}],"wp:attachment":[{"href":"https:\/\/www.prasadk.com\/my-press\/wp-json\/wp\/v2\/media?parent=850"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.prasadk.com\/my-press\/wp-json\/wp\/v2\/categories?post=850"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.prasadk.com\/my-press\/wp-json\/wp\/v2\/tags?post=850"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}