<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Beyond Coding on Medium]]></title>
        <description><![CDATA[Stories by Beyond Coding on Medium]]></description>
        <link>https://medium.com/@beyondcoding.dev?source=rss-78c0b4d22ac5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*kYTRUMHHaMtZC4rH</url>
            <title>Stories by Beyond Coding on Medium</title>
            <link>https://medium.com/@beyondcoding.dev?source=rss-78c0b4d22ac5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 12:18:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@beyondcoding.dev/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[JavaScript Engine — JavaScript Interview Questions & Answers — Part 7]]></title>
            <link>https://medium.com/@beyondcoding.dev/javascript-engine-javascript-interview-questions-answers-part-7-d00a3dea82bd?source=rss-78c0b4d22ac5------2</link>
            <guid isPermaLink="false">https://medium.com/p/d00a3dea82bd</guid>
            <category><![CDATA[javascript-engine]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[javascript-development]]></category>
            <dc:creator><![CDATA[Beyond Coding]]></dc:creator>
            <pubDate>Sun, 04 Oct 2026 07:05:02 GMT</pubDate>
            <atom:updated>2026-10-04T07:05:02.521Z</atom:updated>
            <content:encoded><![CDATA[<p>Every browser has a JavaScript Engine that is responsible for executing JavaScript code. For example, Google Chrome uses the V8 JavaScript engine. Other browsers use different engines, such as Spider Monkey in Firefox and JavaScript Core in Safari.</p><p>JavaScript engines need to implement the ECMAScript specification, which defines the standard for the JavaScript language. ECMAScript is the language specification, while JavaScript is the most well-known implementation of that specification.</p><p>Google’s V8 JavaScript engine is primarily written in C++. Its job is to take JavaScript code and execute it by generating machine code that the computer can execute.</p><p><strong>How JavaScript Engine Works:</strong></p><p>The JavaScript engine takes JavaScript source code as input and goes through several major stages, including parsing, compilation, and execution.</p><p><strong>Parsing: </strong>During parsing, the JavaScript source code is broken down into smaller units called tokens. The parser analyses these tokens and generates an AST (Abstract Syntax Tree). The AST represents the structure and meaning of the JavaScript code.</p><p><strong>JIT Compilation: </strong>Modern JavaScript engines generally use a combination of interpretation and compilation. This approach is commonly known as JIT (Just-In-Time) compilation.</p><p>For example, the V8 engine can start executing JavaScript code quickly and monitor the code while it is running. When it identifies code that is executed frequently, the compiler can optimize that code and generate more efficient machine code.</p><p>AOT (Ahead-of-Time) Compilation: It is a process where code is compiled before the application runs, typically during the build process. For example, Angular can compile application code and templates during the build, so the browser receives already-compiled JavaScript. This is different from JIT compilation.</p><p><strong>Execution:</strong> Once the JavaScript engine has code that can be executed, it manages the execution of JavaScript using Memory Heap and Call Stack.</p><p>Memory Heap: The Memory Heap is an area of memory used by the JavaScript engine to store objects and other dynamically allocated data.</p><p><strong>Interpreter Vs Compiler:</strong></p><p>Interpreter: An interpreter takes the parsed code and starts executing it without first compiling the entire program into optimized machine code, which helps reduce the initial execution time.</p><p>Compiler: Compiler analyses the code and generates a more optimized machine code that can be executed efficiently by the CPU. Compilation can take some time, but the optimized code can execute faster, especially when the same code runs repeatedly.</p><p><strong>JavaScript Runtime Environment:</strong></p><p>A JavaScript Runtime Environment provides everything required to execute JavaScript code and interact with the outside environment. A JavaScript runtime environment generally consists of:</p><ul><li>JavaScript Engine — Executes JavaScript code.</li><li>Runtime APIs — Provide additional functionalities to interact with the environment.</li><li>Call Stack — Keeps track of currently executing JavaScript functions.</li><li>Event Loop — Manages the execution of asynchronous callbacks.</li><li>Task/Callback Queue — Holds tasks that are ready to be executed.</li><li>Micro task Queue — Holds micro tasks such as Promise callbacks.</li></ul><p>A browser provides a JavaScript runtime environment, which allows JavaScript code to execute and interact with the browser, such as the DOM, timers, network requests, storage, and other browser features. Node.js also provides a JavaScript runtime environment, allowing JavaScript to run outside the browser. Both browsers and Node.js provide JavaScript runtime environments, but they provide different environment-specific APIs.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d00a3dea82bd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Event Loop in JavaScript — JavaScript Interview Questions & Answers — Part 6]]></title>
            <link>https://medium.com/@beyondcoding.dev/event-loop-in-javascript-javascript-interview-questions-answers-part-6-f1c138bf1fd1?source=rss-78c0b4d22ac5------2</link>
            <guid isPermaLink="false">https://medium.com/p/f1c138bf1fd1</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[javascript-event-loop]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <dc:creator><![CDATA[Beyond Coding]]></dc:creator>
            <pubDate>Sat, 19 Sep 2026 04:59:30 GMT</pubDate>
            <atom:updated>2026-09-19T05:08:21.534Z</atom:updated>
            <content:encoded><![CDATA[<p>Understanding how the event loop works is essential to mastering JavaScript. In this article, we will deep dive into the event loop, different types of tasks in JavaScript.</p><p><strong>Event Loop</strong> manages the execution of asynchronous callbacks.</p><pre>console.log(&quot;start&quot;);<br><br>setTimeout(function (){<br>  console.log(&quot;timer&quot;);<br>}, 5000);<br><br>fetch(&quot;https://api.netflix.com&quot;)<br>.then(() =&gt; {<br>  console.log(&quot;netflix&quot;);<br>});<br><br>console.log(&quot;end&quot;);</pre><p>First, start is printed because console.log(“start”) executes synchronously.</p><p>Next, setTimeout() is executed. Its callback is registered with the Web API environment, and the 5-second timer starts. JavaScript does not wait for those 5 seconds; it immediately moves to the next line.</p><p>Then fetch() is executed. The browser handles the network request through the Web API environment and waits for the response from the server. JavaScript again does not wait for the response and moves to the next line. Finally, end is printed.</p><p>Suppose the Netflix server responds after 1 second. The callback attached to the fetch() promise becomes a micro-task and is placed into the micro-task queue. The micro-task queue has higher priority than the callback/task queue. Therefore, after all synchronous JavaScript code has finished executing and when call stack is empty, the event loop first processes the micro-task queue before processing tasks from the callback queue. So, after 1 second, the fetch() callback executes and prints Netflix.</p><p>After 5 seconds, the setTimeout() callback becomes ready and is placed into the callback/task queue. When call stack is empty and the micro-task queue has no pending tasks, the event loop moves the setTimeout() callback to the call stack, where it executes and prints timer.</p><p><strong>Micro-task Queue vs Callback Queue</strong></p><p>The micro-task queue has higher priority than the callback queue (task queue). Callbacks associated with Promises, such as .then(), .catch(), and .finally() are placed into the micro-task queue. MutationObserver callbacks are also handled as micro-tasks.</p><p>Callbacks from APIs such as setTimeout(), setInterval(), and DOM event listeners are placed into the callback/task queue.</p><p>When the call stack becomes empty, the event loop first processes the pending micro-tasks. It continues processing micro-tasks until the micro-task queue becomes empty. Only then it takes a task from the callback/task queue and put it onto the call stack. For example, if there are three pending micro-tasks, the event loop processes all three micro-tasks before taking the next task from the callback queue.</p><p><strong>When does the Event loop starts?</strong></p><p>The event loop is continuously running as part of the JavaScript runtime environment. It is responsible for checking whether there are pending tasks in the queues and whether the call stack is empty.</p><p><strong>Are only asynchronous web API callbacks are registered in the web API environment?</strong></p><p>Yes, only callbacks associated with asynchronous operations go through the runtime environment and queues. Synchronous callbacks, such as callbacks passed to map(), filter(), and reduce(), are not registered in the Web API environment.</p><p><strong>Blocking the Main Thread:</strong></p><p>Every piece of JavaScript code runs on the call stack. If some operation blocks the call stack, it is known as blocking the main thread. For example, suppose function x() takes a very long time to execute. JavaScript won’t be able to execute other JavaScript code on that thread until x() finishes because JavaScript has only one main thread. That is why we should avoid blocking the main thread with long-running synchronous operations. We should use asynchronous APIs for operations that involve waiting, such as: Timers, File operations in Node.JS</p><p><strong>Web APIs:</strong></p><p>setTimeout(), DOM APIs such as document.getElementById(), fetch(), localStorage, and console are not part of the JavaScript language itself. They are APIs provided by the browser environment and are commonly referred as Web APIs. The browser provides a JavaScript engine to execute JavaScript code. In addition to the JavaScript engine, the browser provides Web APIs that JavaScript can interact with. In the browser, window is the global object. Browser-provided APIs and global properties are exposed through the window object.</p><p><strong>JavaScript Interview Questions &amp; Answers — Series</strong></p><ul><li><a href="https://medium.com/@beyondcoding.dev/javascript-interview-questions-answers-part-1-704dba2c580d">Part 1: JavaScript Interview Questions &amp; Answers</a></li><li><a href="https://medium.com/@beyondcoding.dev/var-let-and-const-javascript-interview-questions-answers-part-2-4d2425dc0edb">Part 2: JavaScript Interview Questions &amp; Answers</a></li><li><a href="https://medium.com/@beyondcoding.dev/scope-block-block-scope-javascript-interview-questions-answers-part-3-1055eea044f5">Part 3<strong>:</strong> JavaScript Interview Questions &amp; Answers</a></li><li><a href="https://medium.com/@beyondcoding.dev/closures-javascript-interview-questions-answers-part-4-ffd4009c5ec9">Part 4: JavaScript Interview Questions &amp; Answers</a></li><li><a href="https://medium.com/@beyondcoding.dev/types-of-functions-javascript-interview-questions-answers-part-5-8d3eccd5a037">Part 5: JavaScript Interview Questions &amp; Answers</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f1c138bf1fd1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Types of Functions— JavaScript Interview Questions & Answers — Part 5]]></title>
            <link>https://medium.com/@beyondcoding.dev/types-of-functions-javascript-interview-questions-answers-part-5-8d3eccd5a037?source=rss-78c0b4d22ac5------2</link>
            <guid isPermaLink="false">https://medium.com/p/8d3eccd5a037</guid>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[interview]]></category>
            <dc:creator><![CDATA[Beyond Coding]]></dc:creator>
            <pubDate>Fri, 11 Sep 2026 17:51:49 GMT</pubDate>
            <atom:updated>2026-09-19T04:34:28.844Z</atom:updated>
            <content:encoded><![CDATA[<pre>a();<br>b();<br><br>// Function Statement<br>function a(){<br>  console.log(&quot;a called&quot;);<br>}<br><br>//Function Declaration<br>var b = function(){<br>  console.log(&quot;b called&quot;);<br>}</pre><p>First function is called a <strong>Function Statement</strong>, and the second one is called a <strong>Function Expression</strong> or <strong>Function Declaration</strong>.</p><p>The main difference between them is hoisting. A Function Statement is completely hoisted, so we can call a() before its declaration. However, in a Function Expression, the variable b is hoisted but its value is initially undefined. Therefore, calling b() before the assignment will result in a Type Error: b is not a function.</p><p><strong>Anonymous function</strong>:</p><p>A function without a name. It is generally used where a function is expected as a value, such as in a function expression or as a callback.</p><pre>function (){<br>  console.log(&quot;called&quot;);<br>}</pre><p>The above code will throw a Syntax Error because a standalone function declaration must have a name. An anonymous function needs to be used where a function is expected as a value, for example:</p><pre>var a = function (){<br>  console.log(&quot;a called&quot;);<br>}</pre><p><strong>Named function expression</strong>:</p><p>It is like a Function Expression, but instead of using an anonymous function, we give a name.</p><pre>var a = function b(){<br>  console.log(&quot;a called&quot;);<br>}<br>a();<br>b(); // Reference Error</pre><p>For a named function expression, the function is called using the variable that stores it, such as a(), not b(), when calling it from outside. We cannot call b() outside because the name b is available only inside the function body. It is not created as a variable in the outer scope.</p><p><strong>First Class Function/Citizens</strong>:</p><p>The ability to treat functions as values — such as assigning them to a variable, passing them as arguments to another function, and returning them from a function — is known as First-Class Function behavior.</p><pre>const greet = () =&gt; { <br>  console.log(&quot;Hello&quot;); <br>}<br>execute(greet);</pre><p><strong>Higher Order Function:</strong></p><p>A functions that take one or more functions as arguments or return a function.</p><pre>execute(fn) { <br>  fn(); <br>}<br><br>execute(function () =&gt; {<br>  console.log(&quot;callback function&quot;);<br>});</pre><p><strong>Call Back functions:</strong></p><p>We can take a function and pass it into another function. The function that we pass into another function is known as a callback function.</p><p>Synchronous Callbacks:</p><pre>function x(y){<br>  console.log(&quot;x&quot;);<br>  y();<br>}<br><br>x(function y(){<br>  console.log(&quot;y&quot;);<br>});</pre><p>Synchronous callbacks execute immediately during the execution of the function that receives it.</p><p>Asynchronous Callbacks:</p><pre>setTimeout(function(){<br>  console.log(&quot;timer&quot;);<br>}, 5000);<br><br>function x(y){<br>  console.log(&quot;x&quot;);<br>  y();<br>}<br><br>x(function y(){<br>  console.log(&quot;y&quot;);<br>})</pre><p>JavaScript is a synchronous, single-threaded language, which means it has one main thread and one call stack. However, with the help of the JavaScript runtime environment, we can perform asynchronous operations. When we execute this code, first it will print x and y. After all synchronous JavaScript code has finished executing, the call stack becomes empty. After the timer reaches 5 seconds, its setTimeout callback becomes eligible to execute. Callback is moved to the call stack and executed.</p><p><strong>Difference Between Parameters and Arguments</strong></p><p><strong>Parameters:</strong> The variables defined in a function’s declaration that receive the values.</p><pre>function add(param1, param2) {<br>  return param1 + param2;<br>}</pre><p><strong>Arguments:</strong> The actual values passed to the function when it is called.</p><pre>const arg1 = 2;<br>const arg2 = 4;<br>add(arg1, arg2);</pre><p><strong>JavaScript Interview Questions &amp; Answers — Series</strong></p><ul><li><a href="https://medium.com/@beyondcoding.dev/javascript-interview-questions-answers-part-1-704dba2c580d">Part 1: JavaScript Interview Questions &amp; Answers</a></li><li><a href="https://medium.com/@beyondcoding.dev/var-let-and-const-javascript-interview-questions-answers-part-2-4d2425dc0edb">Part 2: JavaScript Interview Questions &amp; Answers</a></li><li><a href="https://medium.com/@beyondcoding.dev/scope-block-block-scope-javascript-interview-questions-answers-part-3-1055eea044f5">Part 3<strong>:</strong> JavaScript Interview Questions &amp; Answers</a></li><li><a href="https://medium.com/@beyondcoding.dev/closures-javascript-interview-questions-answers-part-4-ffd4009c5ec9">Part 4: JavaScript Interview Questions &amp; Answers</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8d3eccd5a037" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Closures — JavaScript Interview Questions & Answers — Part 4]]></title>
            <link>https://medium.com/@beyondcoding.dev/closures-javascript-interview-questions-answers-part-4-ffd4009c5ec9?source=rss-78c0b4d22ac5------2</link>
            <guid isPermaLink="false">https://medium.com/p/ffd4009c5ec9</guid>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[javascript-interview]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[closure]]></category>
            <dc:creator><![CDATA[Beyond Coding]]></dc:creator>
            <pubDate>Tue, 08 Sep 2026 12:39:13 GMT</pubDate>
            <atom:updated>2026-09-08T12:46:33.978Z</atom:updated>
            <content:encoded><![CDATA[<p>A function is bundled with its lexical environment is known as closure. Even when the function is returned from another function and even if it’s vanished in execution context, it still remembers the reference it was pointing to and can access its lexical environment.</p><pre>function x(){<br>  var a = 10;<br>  function y(){<br>    console.log(a);<br>  }<br>  return y;<br>}<br>const z = x();<br>z();<br><br>Output:<br>10</pre><p>This will print 10.</p><blockquote><a href="https://medium.com/@beyondcoding.dev/scope-block-block-scope-javascript-interview-questions-answers-part-3-1055eea044f5">If you’re confuse, read my blog on Lexical Environment for a detailed explanation.</a></blockquote><pre>function x(){<br>  for(var i = 1; i&lt; = 5; i++){<br>    setTimeout(()=&gt; {<br>      console.log(i);<br>    }, i * 1000);<br>  }<br>}<br>x();<br><br>Output:<br>6<br>6<br>6<br>6<br>6</pre><p>With var, the loop creates only one i variable, so all the setTimeout callbacks refer to the same i. By the time the timers execute, the loop has completed and i has become 6, so it prints 6 every time.</p><pre>for(let i = 1; i &lt;= 5; i++){<br>    setTimeout(()=&gt; {<br>      console.log(i);<br>    }, i * 1000);<br>  }<br>}<br>x();<br><br>Output:<br>1<br>2<br>3<br>4<br>5</pre><p>With let, a new i is created for each loop iteration because let is <strong>block scoped</strong>. Each callback forms a closure with its own value of i, so it prints 1, 2, 3, 4, 5 at one-second intervals.</p><pre>function x(){<br>  for(var i = 1; i&lt; = 5; i++){<br>    function close(delayInSeconds){<br>      setTimeout(()=&gt; {<br>        console.log(delayInSeconds);<br>      }, delayInSeconds * 1000);<br>    }<br>    close(i);<br>  }<br>}<br>x();<br><br>Output:<br>1<br>2<br>3<br>4<br>5</pre><p>We can also fix the var example by passing i to a separate function. This creates a new variable (delayInSeconds) for each function call, so each callback forms a closure with its own value of i.</p><p>In JavaScript, closures allow us to achieve data hiding by keeping variables private and accessible only through specific functions.</p><pre>function counter(){<br>  var count = 0;<br>  return function increment(){<br>    count++;<br>    console.log(count);  <br>  }<br>}<br>var counter1 = counter();<br>counter1.increment(); // 1<br>counter1.increment(); // 2<br><br>var counter2 = counter();<br>counter2.increment(); // 1</pre><p>Data hiding means keeping a variable private so that other functions or pieces of code cannot directly access or modify it. In this example, count is hidden inside the counter function and is not directly accessible from outside. The returned increment function can access and modify count through the closure.</p><p><strong>Disadvantage of closures:</strong></p><p>Main disadvantage is <strong>Overconsumption of memory</strong>. The variables captured by a closure are not garbage collected if they are still being referenced by the closure.</p><p><strong>What is Garbage Collector?</strong></p><p>It is a program built into the browser or JavaScript Engine that automatically frees up memory occupied by objects and variables that are no longer being used or referenced.</p><pre>function x(){<br>  var a= 10; b = 20;<br>  function y(){<br>    console.log(a);<br>  }<br>  return y;<br>}<br>x()();</pre><p>When a function is returned, it can form a closure with the outer function’s scope. However, modern JavaScript Engines such as V8 can optimize this and retain only the variables that are needed by the returned function. In this example, a is retained because the inner function uses it, while b can be garbage collected because it is never used.</p><p><strong>JavaScript Interview Questions &amp; Answers — Series</strong></p><ul><li><a href="https://medium.com/@beyondcoding.dev/javascript-interview-questions-answers-part-1-704dba2c580d">Part 1: JavaScript Interview Questions &amp; Answers</a></li><li><a href="https://medium.com/@beyondcoding.dev/var-let-and-const-javascript-interview-questions-answers-part-2-4d2425dc0edb">Part 2: JavaScript Interview Questions &amp; Answers</a></li><li><a href="https://medium.com/@beyondcoding.dev/scope-block-block-scope-javascript-interview-questions-answers-part-3-1055eea044f5">Part 3<strong>:</strong> JavaScript Interview Questions &amp; Answers</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ffd4009c5ec9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Scope, Block & Block Scope — JavaScript Interview Questions & Answers — Part 3]]></title>
            <link>https://medium.com/@beyondcoding.dev/scope-block-block-scope-javascript-interview-questions-answers-part-3-1055eea044f5?source=rss-78c0b4d22ac5------2</link>
            <guid isPermaLink="false">https://medium.com/p/1055eea044f5</guid>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[javascript-frameworks]]></category>
            <category><![CDATA[javascript-interview]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Beyond Coding]]></dc:creator>
            <pubDate>Thu, 03 Sep 2026 14:49:21 GMT</pubDate>
            <atom:updated>2026-09-03T14:54:46.635Z</atom:updated>
            <content:encoded><![CDATA[<p>In this part, we’ll explore <strong>Scope, Blocks, and Block Scope in JavaScript</strong> — key concepts that are frequently asked in JavaScript interviews and essential for writing predictable code.</p><h4>What is Scope?</h4><p>Scope refers to where a variable or function can be accessed in our code. In JavaScript, scope is directly related to the <strong>lexical environment</strong>. A lexical environment is created when an execution context is created. It contains the local variables, functions, and a reference to the lexical environment of its parent.</p><pre>function a(){<br>  c();<br>  function c(){<br>    console.log(b);<br>  }<br>}<br>var b = 10;</pre><p>First, JavaScript looks for b in the local memory of function c(). It doesn’t find b because b is not declared inside c(). The JavaScript Engine then looks at the lexical environment of the parent. Since c() is defined inside a(), the lexical parent of c() is a(). Therefore, it searches for b in the lexical environment of a(). It doesn’t find b inside a() either, so it moves to the lexical environment of a()’s parent, which is the Global Execution Context. Here, it finds b and gets its value, which is 10.</p><p>If b is not found in the Global Execution Context either, there is no further parent lexical environment because the global environment’s parent is null. At that point, JavaScript throws a Reference Error, such as: Reference Error: b is not defined</p><p>The <strong>Scope Chain</strong> is the chain of lexical environments created through their parent references. It allows JavaScript to look for variables and functions from the current lexical environment up through its parent environments until it finds the required identifier or reaches the end of the chain.</p><h4><strong>What is Block &amp; Block Scope?</strong></h4><p>Block is used to group multiple JavaScript statement into a single group. Block scope means what are variables and functions we can access inside this block.</p><pre>var condition = true;<br>if(condition) {<br>  var a = 10;<br>  var b = 20;<br>}<br>console.log(a);<br>console.log(b);</pre><p>The variable a, declared using var, can be accessed outside the block, so console.log(a) will print 10. However, b, declared using let, is block-scoped, so it cannot be accessed outside the block and will give a Reference Error: b is not defined.</p><p>var is <strong>function-scoped</strong>, while let and const are <strong>block-scoped</strong>.</p><pre>function abc() {<br>  var a = 10;<br>  var b = 20;<br>}<br>abc();<br>console.log(a);</pre><p>Here, a will also give an error because var is function scoped. The function creates a separate execution context, so the variables declared inside the function cannot be accessed outside it. Therefore, console.log(a) will give a Reference Error: a is not defined.</p><pre>var condition = true;<br>var a = 100;<br>var b = 200;<br>if(condition) {<br>  var a = 10;<br>  var b = 20;<br>}<br>console.log(a);<br>console.log(b);</pre><p>a will print 10, b will print 200. This is called <strong>shadowing</strong>.</p><p>Shadowing means creating a variable with the same name as a variable in the outer scope.</p><p><strong>JavaScript Interview Questions &amp; Answers — Series</strong></p><ul><li><a href="https://medium.com/@beyondcoding.dev/javascript-interview-questions-answers-part-1-704dba2c580d">Part 1: JavaScript Interview Questions &amp; Answers</a></li><li><a href="http://medium.com/@beyondcoding.dev/var-let-and-const-javascript-interview-questions-answers-part-2-4d2425dc0edb">Part 2: JavaScript Interview Questions &amp; Answers</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1055eea044f5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Var, Let and Const — JavaScript Interview Questions & Answers — Part 2]]></title>
            <link>https://medium.com/@beyondcoding.dev/var-let-and-const-javascript-interview-questions-answers-part-2-4d2425dc0edb?source=rss-78c0b4d22ac5------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d2425dc0edb</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[variables]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[javascript-interview]]></category>
            <dc:creator><![CDATA[Beyond Coding]]></dc:creator>
            <pubDate>Sun, 30 Aug 2026 07:41:21 GMT</pubDate>
            <atom:updated>2026-08-31T05:39:57.892Z</atom:updated>
            <content:encoded><![CDATA[<p>Let and const declarations are stored in the separate memory space allocated for their specific block/lexical environment and are not added as properties of the global object (window in a browser). var declarations, on the other hand, become properties of the global object when declared in the global scope of a traditional browser script.</p><p>Let and const declarations are hoisted, but unlike var, they are not initialized with undefined. They remain in the Temporal Dead Zone (TDZ) from the beginning until they are initialized. The Temporal Dead Zone is the time between let or const declaration and the point where the variable is initialized.</p><pre>console.log(a);<br>let a = 10;<br>var b = 20;</pre><p>Here, a is hoisted but remains uninitialized. When we try to access a before its initialization, JavaScript throws a Reference Error: Cannot access ‘a’ before initialization. Once a is initialized with 10, we can access it normally.</p><p>If we try to access b before its initialization, it will print undefined because var is hoisted and initialized with undefined.</p><p>If we try to access a variable that is not declared anywhere in the program, JavaScript throws Reference Error: x is not defined.</p><pre>let a = 10;<br>let a = 5;<br>var b = 20;</pre><p>If we try to re-declare a let variable in the same scope, JavaScript throws Syntax Error: Identifier ‘a’ has already been declared. This error occurs before executing any code.</p><pre>let a = 10;<br>var a = 20;</pre><p>We cannot declare the same variable name using let and var in the same scope.</p><pre>let a = 10;<br>var b = 20;<br>var b = 30;</pre><p>However, var allows re-declaration.</p><pre>let a;<br>a = 10;<br>const b;<br>b = 20;</pre><p>Let can be declared without an initial value and assigned a value later. But const must be initialized when it is declared. This throws Syntax Error: Missing initializer in const declaration.</p><pre>const b = 10;<br>b = 20;</pre><p>Once a const variable is initialized, it cannot be reassigned. This throws Type Error: Assignment to constant variable.</p><blockquote>A good practice is to declare and initialize variables before using them to avoid accessing let and const variables while they are in the Temporal Dead Zone.</blockquote><pre>var condition = true;<br>if(condition) {<br>  var a = 10;<br>  let b = 20;<br>}<br>console.log(a);<br>console.log(b);</pre><p>The variable a declared using var, can be accessed outside the block, so console.log(a) will print 10. However, b declared using let, is block-scoped, so it cannot be accessed outside the block and will give a Reference Error: b is not defined.</p><blockquote>var is function-scoped, while let and const are block-scoped.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d2425dc0edb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript Interview Questions & Answers— Part 1]]></title>
            <link>https://medium.com/@beyondcoding.dev/javascript-interview-questions-answers-part-1-704dba2c580d?source=rss-78c0b4d22ac5------2</link>
            <guid isPermaLink="false">https://medium.com/p/704dba2c580d</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[javascript-interview]]></category>
            <category><![CDATA[frontend-development]]></category>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[interview-questions]]></category>
            <dc:creator><![CDATA[Beyond Coding]]></dc:creator>
            <pubDate>Tue, 25 Aug 2026 17:33:25 GMT</pubDate>
            <atom:updated>2026-09-03T14:56:24.752Z</atom:updated>
            <content:encoded><![CDATA[<p>In this part, we’ll explore concepts that are frequently asked in JavaScript interviews and essential for writing predictable code.</p><h4><strong>What does it mean that JavaScript is synchronous and single-threaded?</strong></h4><p>JavaScript is a synchronous single-threaded language. Synchronous single threaded means JavaScript can only execute one command at a time and in a specific order. So that means it can go the next line once the current line has been finished executing.</p><h4><strong>What happens internally when you run a JavaScript program?</strong></h4><p>Every piece of JavaScript code executes inside an <strong>Execution Context</strong>. When you run a JavaScript program, <strong>Global Execution Context </strong>is created. This execution is created in two phases.</p><p>First phase is known as <strong>Memory Creation</strong> phase. JavaScript scans the entire program before executing any code. It allocates memory to all variables and functions. Variables are initially assigned a special value called undefined. In case of functions, the entire function is stored in memory.</p><p>Second phase is <strong>Code Execution </strong>phase. JavaScript runs program again, line by line and starts executing the code. During this phase, variables are assigned their actual values and functions are invoked whenever they are called. Whenever a new function is invoked, a new execution context is created. Once the function has finished executing, its execution context is deleted. Once the entire program finishes execution, the global execution is deleted.</p><h4><strong>What is the Call Stack in JavaScript, and how does it work?</strong></h4><p><strong>Call stack</strong> is a stack data structure that manages execution context created during the execution of a JavaScript program. The Global Execution Context is always the first execution context created, so it is placed at the bottom of the stack. Whenever a new function is invoked or a new execution context is created, that execution context is push onto the stack. Once we are done with executing the function, newly created execution context is popped from the stack and control goes back to the global execution context, where it left off. This process continues for every function call until the entire JavaScript program has finished executing. At that point, the Global Execution Context is also removed, and the Call Stack becomes empty.</p><p>The Call Stack is responsible for managing execution contexts and maintaining the correct order of execution throughout the program.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*Mywnl8ycC6jwGPut.png" /><figcaption>JavaScript Call Stack &amp; Execution Contexts</figcaption></figure><blockquote>Refer to this article for a detailed explanation with examples:</blockquote><blockquote><a href="https://medium.com/@beyondcoding.dev/what-happens-when-you-run-javascript-program-e14a0cc8f400"><em>How JavaScript Works? What happens when you run JavaScript program?</em></a></blockquote><h4><strong>What is Hoisting in JavaScript?</strong></h4><p>With <strong>hoisting </strong>we can access variables and functions even before we have initialized it or we put some value in it.</p><pre>console.log(a);<br>var a = 10;</pre><h4><strong>What is window and this in JavaScript?</strong></h4><p><strong>Window </strong>is the global object provided by browser environment. When we run a JavaScript program, the JavaScript Engine creates and manages the Global Execution Context, and the Global Execution Context has a global “<strong>this</strong>” binding that refers to the window object in a traditional browser script.</p><h4><strong>What is the difference between undefined and not defined in JavaScript?</strong></h4><p><strong>Undefined </strong>is a special value in JavaScript that represents a variable or property that has been declared but has not yet been assigned a value. Until a value is assigned, its value remains undefined.</p><p><strong>Not defined </strong>means that a variable has not been declared at all in the accessible scope. Accessing such a variable results in a Reference error.</p><pre>var a;<br>console.log(a); // undefined<br>console.log(b); // Reference Error: b is not defined</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=704dba2c580d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implement GraphQL Subscription in Angular/NativeScript Angular Applications]]></title>
            <link>https://medium.com/@beyondcoding.dev/implement-graphql-subscription-in-angular-nativescript-angular-applications-f9fa594ead60?source=rss-78c0b4d22ac5------2</link>
            <guid isPermaLink="false">https://medium.com/p/f9fa594ead60</guid>
            <category><![CDATA[nativescript]]></category>
            <category><![CDATA[apollo]]></category>
            <category><![CDATA[graphql-subscriptions]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[nativescript-angular]]></category>
            <dc:creator><![CDATA[Beyond Coding]]></dc:creator>
            <pubDate>Wed, 19 Aug 2026 18:29:44 GMT</pubDate>
            <atom:updated>2026-08-19T18:29:44.324Z</atom:updated>
            <content:encoded><![CDATA[<p>GraphQL subscriptions allow an application to receive real-time updates from a GraphQL server.</p><p>Unlike queries and mutations, where the client sends a request and waits for a response, subscriptions allow the server to push new data to the client whenever an event occurs.</p><p>In this article, we’ll see how to implement GraphQL subscriptions in a <strong>NativeScript + Angular</strong> application using Apollo Client and graphql-ws.</p><h3><strong>1. Install </strong><strong>graphql-ws</strong></h3><pre>npm intstall graphql-ws<br>or<br>yarn add graphql-ws</pre><p>graphql-ws provides the WebSocket-based transport required for GraphQL subscriptions.</p><h4><strong>HTTP vs WebSocket</strong></h4><p>Before looking at the implementation, it’s important to understand why WebSockets are required for subscriptions.</p><p><strong>HTTP — Standard Web Requests</strong></p><p>With a normal HTTP request:</p><ul><li>The front-end sends a request to the server.</li><li>The server processes the request.</li><li>The server sends a respnse.</li><li>The HTTP request is completed.</li></ul><p><strong>WebSockets</strong></p><p>With WebSockets, the client and server establish a persistent connection. Once the connection is established, both sides can send messages at any time. This makes WebSockets a good fit for real-time features such as:</p><ul><li>GraphQL subscriptions</li><li>Live notifications</li><li>Chat applications</li><li>Real-time dashboards</li><li>Live status updates</li></ul><h3>2. Configure Apollo Client</h3><p>Let’s look at how to add support for this transport to Apollo Client.</p><p>We need two different links in Apollo Client:</p><ul><li>An <strong>HTTP link</strong> for queries and mutations</li><li>A <strong>WebSocket link</strong> for subscriptions</li></ul><pre>provideApollo(() =&gt; {<br>      // Create an http link:<br>      const httpLink = inject(HttpLink).create({<br>        uri: &quot;http://graphql-server/graphql&quot;<br>      });<br><br>      // Create a WebSocket link:<br>      const wsLink = new GraphQLWsLink(<br>        createClient({<br>          url: &quot;ws://graphql-server/graphql&quot;,<br>          lazy: true,<br>          retryAttempts: Infinity<br>        })<br>      );<br><br>      const link = split(<br>        ({ query }) =&gt; {<br>          const definition = getMainDefinition(query);<br><br>          return (<br>            definition.kind === Kind.OPERATION_DEFINITION &amp;&amp;<br>            definition.operation === OperationTypeNode.SUBSCRIPTION<br>          );<br>        },<br>        wsLink,<br>        httpLink<br>      );<br><br>      return {<br>        link: link,<br>        cache: new InMemoryCache({})<br>      };<br>    })</pre><p><strong>What does split do?</strong></p><p>Apollo’s split() has essentially this structure:</p><pre>split(condition, trueLink, falseLink)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/1*BSksvqJq9Jq2Kf19Py22MQ.png" /></figure><p>If the condition returns true, Apollo uses wsLink. If it returns false, Apollo uses httpLink.</p><p><strong>Understanding getMainDefinition(query)</strong></p><pre>const definition = getMainDefinition(query);</pre><p>Extracts the main operation definition from the GraphQL AST.</p><p>We then check:</p><pre>definition.kind === Kind.OPERATION_DEFINITION</pre><p>This verifies that the definition represents a GraphQL operation.</p><p>Next, we check:</p><pre>definition.operation === OperationTypeNode.SUBSCRIPTION</pre><p>This determines whether the operation is a subscription.</p><p>Therefore:</p><ul><li><strong>Query</strong> → httpLink</li><li><strong>Mutation</strong> → httpLink</li><li><strong>Subscription</strong> → wsLink</li></ul><h3>4. Why does this work in Angular Web applications but fail in NativeScript?</h3><p>Because graphql-ws does this internally:</p><pre>createClient({<br>  url: &#39;ws://...&#39;<br>})</pre><p>In a normal browser, graphql-ws can use the browser&#39;s global WebSocket. But in your <strong>NativeScript + Angular</strong> environment, there isn’t a browser-style global WebSocket available to graphql-ws.</p><p><strong>Add WebSocket support to NativeScript</strong></p><p>To provide WebSocket functionality in NativeScript, install:</p><pre>npm install @valor/nativescript-websockets<br>or<br>yarn add @valor/nativescript-websockets</pre><p>Then import the package in main.ts.</p><pre>import &#39;@valor/nativescript-websockets&#39;;</pre><h3>5. Android: ReferenceError: okhttp3 is not defined</h3><p>After adding the NativeScript WebSocket implementation, you may encounter another error on Android:</p><p><em>ReferenceError: okhttp3 is not defined</em></p><p>The NativeScript WebSocket implementation uses Android’s native networking stack through <strong>OkHttp</strong>. If the required OkHttp classes are not available in the Android application’s classpath, the NativeScript JavaScript layer may fail when it tries to access classes from the okhttp3 package.</p><p>In that situation, you need to add the OkHttp dependency to your Android application.</p><p>Add below in app.gradle file.</p><pre>dependencies {<br>    implementation &quot;com.squareup.okhttp3:okhttp:4.9.3&quot;<br>}</pre><p>Then rebuild the Android application.</p><p><strong>What is OkHttp?</strong></p><p>OkHttp is an HTTP and networking library for Android/JVM applications.</p><p>It provides functionality such as:</p><ul><li>HTTP requests</li><li>HTTPS</li><li>WebSocket connections</li><li>Connection pooling</li><li>TLS support</li><li>Network connection management</li></ul><p>In this setup, OkHttp provides the native Android networking implementation required by the NativeScript WebSocket plugin.</p><blockquote>With these pieces in place, Apollo Client can use <strong>HTTP for queries and mutations</strong> and <strong>WebSockets for GraphQL subscriptions</strong> in a NativeScript Angular application.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f9fa594ead60" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How JavaScript Works? What happens when you run JavaScript program?]]></title>
            <link>https://medium.com/@beyondcoding.dev/what-happens-when-you-run-javascript-program-e14a0cc8f400?source=rss-78c0b4d22ac5------2</link>
            <guid isPermaLink="false">https://medium.com/p/e14a0cc8f400</guid>
            <category><![CDATA[javascript-call-stack]]></category>
            <category><![CDATA[javascript-engine]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[execution-context]]></category>
            <dc:creator><![CDATA[Beyond Coding]]></dc:creator>
            <pubDate>Fri, 31 Jul 2026 17:15:44 GMT</pubDate>
            <atom:updated>2026-08-01T15:02:58.785Z</atom:updated>
            <content:encoded><![CDATA[<p>When you run a JavaScript program, the JavaScript Engine creates a <strong>Global Execution Context</strong> <strong>(GEC)</strong>. Every piece of JavaScript code executes inside an <strong>Execution context</strong>.</p><p>This <strong>Execution Context </strong>is created in two phases.</p><h4><strong>Phase 1: Memory Creation Phase</strong></h4><p>During this phase, JavaScript scans the entire program before executing any code and JavaScript will allocate memory to all the variables and functions.</p><ul><li>Variables are allocated memory and initialized with the value <em>undefined.</em></li><li>In case of functions, it will stored complete function definition.</li></ul><p>This phase is known as <strong>Memory Creation phase </strong>or <strong>Variable Environment.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9kR3jnSAPB-fLZ_ZCz_sZw.png" /><figcaption>Memory Allocation</figcaption></figure><h4><strong>Phase 2: Code Execution phase</strong></h4><p>JavaScript once again run this whole JavaScript program line by line and it starts executing code now.</p><p>During this phase:</p><ul><li>Variables are assigned their actual values</li><li>Functions are invoked whenever they are called</li></ul><p>Whenever is new function is invoked, JavaScript creates a new execution context. This execution context has its own memory and execution environment.</p><p>When the whole function is executed, this whole execution context for that instance of this function will be deleted.</p><p>This phase is known as <strong>Code Execution Phase </strong>or<strong> Thread of Execution</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/262/1*uFCoAggYFGo-P2l8oIsnTQ.png" /><figcaption>Function Execution Context</figcaption></figure><h4>Call Stack:</h4><p>So far, we’ve learned that JavaScript creates a <strong>Global Execution Context</strong> when a program starts, and every time a function is invoked, a <strong>new Function Execution Context</strong> is created.</p><p>But how does JavaScript keep track of all these execution contexts?</p><p>The answer is the <strong>Call Stack</strong>.</p><p>The <strong>Call Stack</strong> is a stack data structure that manages the execution contexts created during the execution of a JavaScript program. The <strong>Global Execution Context</strong> is always the first execution context created, so it is placed at the <strong>bottom of the stack</strong>.</p><p>Whenever a function is invoked, JavaScript creates a <strong>new Function Execution Context</strong> and pushes it onto the top of the Call Stack.</p><p>Once the function finishes executing, its execution context is <strong>popped</strong> off the stack, and control returns to the execution context below it.</p><p>This process continues for every function call until the entire JavaScript program has finished executing. At that point, the <strong>Global Execution Context</strong> is also removed, and the <strong>Call Stack becomes empty</strong>.</p><p>The <strong>Call Stack</strong> is responsible for managing execution contexts and maintaining the correct order of execution throughout the program.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AR3Rp4E6XISeMFykP0__AQ.png" /></figure><h4>What happens at the end?</h4><p>Once the entire JavaScript program has finished executing and there is no more code left to run:</p><ul><li>The <strong>Global Execution Context</strong> is removed from the <strong>Call Stack</strong>.</li><li>The <strong>Call Stack</strong> becomes empty, indicating that there are no more execution contexts left to execute.</li><li>The program execution is complete.</li><li>The JavaScript engine releases the resources associated with that execution context.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vqBeNaLnTPrDSUQq-qCdbQ.png" /><figcaption>Execution Context Phases</figcaption></figure><h4>Summary:</h4><p>The lifecycle of a JavaScript program can be summarized as follows:</p><ol><li><strong>Global Execution context</strong> is created.</li><li><strong>Memory Creation Phase</strong> allocates memory for variables and functions.</li><li><strong>Code Execution Phase </strong>executes program line by line.</li><li>Every function call creates a new <strong>Function Execution context</strong>.</li><li>Each new execution context is <strong>pushed onto the Call Stack</strong>.</li><li>Once a function finishes executing, its execution context is <strong>popped off the Call Stack</strong>, and control returns to the previous execution context.</li><li>After the entire program has finished executing, the <strong>Global Execution Context</strong> is removed from the Call Stack.</li><li>Finally, the <strong>Call Stack</strong> becomes empty, indicating that the JavaScript program has completed execution.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/970/1*rrKWy9yrMEZBhqvru7UhpQ.png" /><figcaption>JavaScript Execution Flow</figcaption></figure><p>Questions? Confused about something? That’s totally normal! Drop a comment below, and let’s figure it out together. We’re all learning here.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e14a0cc8f400" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>