{"id":4914,"date":"2024-07-31T11:17:38","date_gmt":"2024-07-31T05:47:38","guid":{"rendered":"https:\/\/namastedev.com\/blog\/?p=4914"},"modified":"2024-07-31T11:17:39","modified_gmt":"2024-07-31T05:47:39","slug":"ep01-how-javascript-works-execution-context","status":"publish","type":"post","link":"https:\/\/namastedev.com\/blog\/ep01-how-javascript-works-execution-context\/","title":{"rendered":"Ep01 | How JavaScript Works &amp; Execution Context ?"},"content":{"rendered":"<h1>Introduction:<\/h1>\n<p>I am writing this article so as I started learning Namaste JavaScript, (which I say you must check out) and I am creating notes via this article for the lecture through my prospective and what I have learned.<\/p>\n<p><\/p>\n<p>So, first of this all there are two important learning&#8217;s of the episode 1 :<\/p>\n<p>A.<strong> Everything in JavaScript happens inside an Execution Context.&nbsp;<\/strong>&nbsp;<\/p>\n<p>B. <strong>JavaScript is a Synchronous Single Threaded language.&nbsp;<\/strong><\/p>\n<p><\/p>\n<p>Now, let us discuss each one of them one by one.<\/p>\n<p><\/p>\n<h1>1. Everything in JavaScript happens inside an Execution Context:<\/h1>\n<p>Yes, it is true that Everything in JavaScript happens inside an Execution Context. But what is Execution Context ?, So you can consider Execution Context like a box inside which all the things are happening in JavaScript.<\/p>\n<p>The Execution Context consists of two parts :<\/p>\n<p>1. Memory Component or Variable Environment .<\/p>\n<p>2. Code Component or Thread of Execution.<\/p>\n<p><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/namastedev.com\/blog\/wp-content\/uploads\/2024\/07\/fig1.png\"><\/p>\n<h2><\/h2>\n<h2>1. Memory Component or Variable Environment:<\/h2>\n<p>This is a component or an environment in which all variables and functions are stored which are in the program as key-value pairs. like :<\/p>\n<p><\/p>\n<pre class=\"ql-syntax\">Let a = 10 ;\nconst foo = () =&gt; { \/\/ execution lines of function };\n<\/pre>\n<p><\/p>\n<p>are stored as :<\/p>\n<p><\/p>\n<pre class=\"ql-syntax\">a : 10,\nfoo : { *whole executable code of function.* },\n<\/pre>\n<p><\/p>\n<h2>2. Code Component or Thread of Execution:<\/h2>\n<p>This is component where whole code is executed one line at a time. It is also known as Thread of Execution, which is smallest unit of programmed instructions given to a computer and can be managed independently.<\/p>\n<p><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/namastedev.com\/blog\/wp-content\/uploads\/2024\/07\/fig2.png\"><\/p>\n<p><\/p>\n<h1>2. JavaScript is Synchronous Single-Threaded language:<\/h1>\n<p>This is one of the most important another fact about the JavaScript that it is Synchronous Single-Threaded language. Now we will each of the word Synchronous Single-Threaded. So, Single-Threaded means JavaScript will execute one command at a time, you can say one thread at that a time, while Synchronous means that it will execute command in specific order, in which it goes to next line once the current line has been finished executing.<\/p>\n<p>So, combining these we can say that JavaScript is Synchronous Single-Threaded language, which execute one line of code at a time in a specific order while going to next line only when the current line of the code has&nbsp;been completely executed.<\/p>\n<p><\/p>\n<p><\/p>\n<p>So, This is my first article. I hope you like that. If you have any doubts and suggestions, do let me know at:&nbsp;<a href=\"https:\/\/linkedin.com\/in\/rahulkumarpahwa\" rel=\"noopener noreferrer\" target=\"_blank\">https:\/\/linkedin.com\/in\/rahulkumarpahwa<\/a>.<\/p>\n<p>Also, I will create a repo for the Namaste JavaScript course I have started where I will post this article as readme. so do check out it at : <a href=\"https:\/\/github.com\/rahulkumarpahwa\" rel=\"noopener noreferrer\" target=\"_blank\">https:\/\/github.com\/rahulkumarpahwa<\/a><\/p>\n<p><\/p>\n<p>Singing off,<\/p>\n<p>Rahul Kumar.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction: I am writing this article so as I started learning Namaste JavaScript, (which I say you must check out) and I am creating notes via this article for the lecture through my prospective and what I have learned. So, first of this all there are two important learning&#8217;s of the episode 1 : A.<\/p>\n","protected":false},"author":41,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[231,172],"tags":[330],"class_list":["post-4914","post","type-post","status-publish","format-standard","category-article","category-javascript","tag-javascript"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/posts\/4914","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/comments?post=4914"}],"version-history":[{"count":1,"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/posts\/4914\/revisions"}],"predecessor-version":[{"id":4917,"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/posts\/4914\/revisions\/4917"}],"wp:attachment":[{"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/media?parent=4914"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/categories?post=4914"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/tags?post=4914"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}