<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Della Dominic</title>
    <description>The latest articles on DEV Community by Della Dominic (@della_codes).</description>
    <link>https://dev.to/della_codes</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3748061%2F60b8a000-fd4d-4ac5-b3af-a683f9542bb6.jpeg</url>
      <title>DEV Community: Della Dominic</title>
      <link>https://dev.to/della_codes</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/della_codes"/>
    <language>en</language>
    <item>
      <title>How JavaScript code runs behind the scenes | Execution Context</title>
      <dc:creator>Della Dominic</dc:creator>
      <pubDate>Wed, 18 Feb 2026 17:07:14 +0000</pubDate>
      <link>https://dev.to/della_codes/how-javascript-code-runs-behind-the-scenes-execution-context-3498</link>
      <guid>https://dev.to/della_codes/how-javascript-code-runs-behind-the-scenes-execution-context-3498</guid>
      <description>&lt;p&gt;Understanding how JavaScript code is executed is crucial whether you are learning the language or working with it regularly. To truly understand how hoisting works, why a ReferenceError is thrown, or in what order your code executes — these are just a few reasons why this concept is important.&lt;/p&gt;

&lt;p&gt;First things first, always remember that JavaScript is a single-threaded, synchronous language. Now what does that mean? In simple terms, single-threaded means JavaScript has only one call stack and can execute one task at a time. This execution happens synchronously i.e. code is executed one ‘after’ the other. The thread of execution executes a line at a time, ‘waits’ for it to complete and then executes the next line.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: JavaScript executes code synchronously by default, but can handle asynchronous operations using the event loop, Web APIs, callbacks, promises, and async/await.&lt;/p&gt;

&lt;p&gt;Note: The call stack follows the Last In, First Out (LIFO) principle.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  What is an Execution Context ?
&lt;/h2&gt;

&lt;p&gt;JavaScript code is executed in an environment called Execution Context. So, whenever a JavaScript program or script runs, an execution context is created to execute the JS code.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: An execution context is also created within the main context when a JavaScript function is called or invoked.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  There are two parts in an execution context:
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Memory part (variable environment)&lt;/strong&gt;: This is where all variables, constants and functions are stored as key-value pairs (we will see how exactly in some time :)&lt;br&gt;
&lt;strong&gt;Thread of execution&lt;/strong&gt;: This is where code is executed one line at a time, one after the other.&lt;/p&gt;
&lt;h3&gt;
  
  
  There are two types of execution context:
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Global Execution Context (GEC)&lt;/strong&gt;: This is the main execution context created for the program, as soon as it starts executing. It contains a global memory and a thread of execution. All top-level code runs inside the Global Execution Context. Remember there is only one global execution context per program. This context is deleted after the program is fully executed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Function Execution Context (FEC)&lt;/strong&gt;: Whenever a function is called or invoked (recognised by the parenthesis next to the function name eg. &lt;code&gt;sum(2,3)&lt;/code&gt; or &lt;code&gt;showSum()&lt;/code&gt;, a new execution context for that function specifically is created inside the global execution context. This function execution context has its own memory space known as local memory and its own thread of execution where every line of code in the ‘function definition’ (till return) is executed. This context is deleted once the return statement in the function is executed or after execution of the last line in the function body (in case there is no return statement) whereupon JavaScript will implicitly return undefined.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: A function execution context has access to its local memory and also the global memory! But the Global execution cannot access a local memory. The global context does not have access to variables declared inside a function, because they are scoped to that function.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
  
  
  An Execution context is created in two phases:
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Phase 1- Memory creation phase&lt;/strong&gt;: This is the phase before the code is actually executed. Initially, each line in the script is parsed and memory is allocated for every defined variable, constant and function. During the memory creation phase, var variables are initialised with undefined. Let and const declarations are hoisted but remain uninitialised in the Temporal Dead Zone until their declaration is executed. Function declarations are fully hoisted with their function definition. During parsing (before execution), syntax errors are detected.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phase 2-Code execution phase&lt;/strong&gt;: Once the memory is allocated in the global space or memory of global execution context, the code is executed in this phase line by line from first line to last, one line after another, one line at a time. This is where thread of execution is created and actual code execution takes place i.e., all calculations are made and &lt;em&gt;resulting values are assigned to existing labels in memory&lt;/em&gt; and function calls are executed (leading to creation of function execution context which again follows these two phases).&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: Why did I emphasise above that the values are assigned to existing labels ? What happens if there are no labels i.e. no allocated memory?&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'use strict';
var num = 5;
numSquare = num * num; // ReferenceError at runtime
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Consider above example, to understand what I meant when I said ‘values are assigned to existing labels in memory’ . What will be the output of the above code? Yes, it will throw a ReferenceError: numSquare is not defined. Well, most of you already know what this means — we are trying to refer to a variable named ‘numSquare’ that is not even defined, hence the error. But now think about how this error is caught in terms of what happens in the execution context. This was caught during run time i.e. during the code execution phase when we were executing line &lt;code&gt;numSquare = num * num;&lt;/code&gt;. What we do here is that we calculate &lt;code&gt;num * num&lt;/code&gt; i.e. &lt;code&gt;5 * 5&lt;/code&gt; which results in &lt;code&gt;25&lt;/code&gt; and now try to assign it to the memory location labelled as &lt;code&gt;numSquare&lt;/code&gt; i.e. we try to assign the calculated value, &lt;code&gt;25&lt;/code&gt; to the existing label, &lt;code&gt;numSquare&lt;/code&gt;. Remember that memory is allocated during the memory creation phase for variables declared using var, let, or const. Since numSquare was never declared, no memory was allocated for it. Therefore, when JavaScript tries to assign a value to it during execution (in strict mode), it throws a ReferenceError.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  How is JavaScript code executed ?
&lt;/h2&gt;

&lt;p&gt;We have learned that JavaScript code is executed in an execution context. Understanding how JavaScript is executed behind the scenes is essentially same as understanding how the execution context is created through the 2 phases in detail. Let’s dive deep with an example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var a = 4;                  //line 1
function multiply(x, y) {     //line 2
    var result = x * y;       //line 3
    return result;            //line 4
}                             //line 5
var b = 5;                    //line 6
var output = multiply(a, b);  //line 7

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s see what happens when the above code is run step by step.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.&lt;/strong&gt; Firstly a global execution context (GEC) is created and pushed into a stack (known as call stack) to keep track of the thread of execution i.e. to keep track of the line of control in the entire program.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Call stack

---&amp;gt;| GEC               |
    ---------------------
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2.&lt;/strong&gt; Next, memory is created for the GEC, (phase 1 of GEC creation). What happens here is that the entire program is ‘parsed’ line by line to allocate space for all defined variables and function. At the end of this phase this is how the global memory would look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a: undefined
multiply: function multiply(x, y) {     
    var result = x * y;       
    return result;            
}
b: undefined
output: undefined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Note: As mentioned earlier, undefined will be assigned initially to all variables and constants — a, b, output. Whereas the entire function code is assigned to the function — multiply.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;3.&lt;/strong&gt; Now, we enter the second phase of GEC creation — thread of execution or code execution phase. This is where the code starts executing starting from line 1.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4.&lt;/strong&gt; Firstly, line 1 is executed. Here, 4 is assigned to the constant ‘a’. So, in the memory space we lookup allocated memory labelled as ‘a’ and assign 4 to it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a: 4
multiply: f // the function's entire code is stored here
b: undefined
output: undefined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5.&lt;/strong&gt; Now moving to line 2, which is a function definition (from line 2 to 5). Nothing to execute here (as it is not a function call but just a definition)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6.&lt;/strong&gt; We have the function definition till line 5. So the next statement to be executed is in line 6, wherein we assign 5 to variable ‘b’. So, in the memory space we lookup allocated memory labelled as ‘b’ and assign 5 to it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a: 4
multiply: f
b: 5
output: undefined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;7.&lt;/strong&gt; On line 7, we are calling the multiply function with the arguments &lt;code&gt;a&lt;/code&gt; , &lt;code&gt;b&lt;/code&gt; and then assign the result returned to the variable output. Here, the function call is first executed. So as we know, here a Function Execution Context (FEC) is created for the function ‘multiply’ and this is also pushed into call stack, with the point of control now pointing to line 2.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Call stack

---&amp;gt;| multiply(4,5)//FEC |
    ---------------------
    |  GEC               |
    ---------------------
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;8.&lt;/strong&gt; Local Memory for the FEC is created by parsing lines 2 to 5 (where function multiply is defined). At the end of this step, the memory of FEC looks like below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x: undefined
y: undefined
result: undefined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note here that, the parameters x and y are also allocated memory.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;9.&lt;/strong&gt; Now begins the thread of execution phase of the FEC i.e. the function’s code execution starting with assigning the arguments a and b that evaluates to 4 and 5 (from the global memory) to the parameters x and y respectively.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x: 4
y: 5
result: undefined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;10.&lt;/strong&gt; Next line 3 is executed where values of x and y are multiplied and assigned to result. So here, 4 * 5 is calculated and the product 20 is assigned to local variable result in the local space.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x: 4
y: 5
result: 20

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;11.&lt;/strong&gt; Now point of control moves to the next line i.e. line 4 where the result is returned. JavaScript looks up result in the function’s local memory and returns it to the Global Execution Context. Two main things happen next. As soon as the return statement is executed the Function execution context is deleted. It is popped out from the call stack and now the control moves back to the GEC to the line where the function was originally invoked.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Call stack

    |                    | ----------&amp;gt; multiply(4,5)//FEC is popped out

---&amp;gt;|  GEC               |
    ---------------------
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;12.&lt;/strong&gt; The control is now back at line 7 where the function has returned the result 20 and this is now assigned to the global variable ‘output’.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a: 4
multiply: function multiply(x, y) {     
    var result = x * y;       
    return result;            
}
b: 5
output: 20
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;13.&lt;/strong&gt; Now the program is fully executed. Therefore the GEC is deleted i.e. it pops out from the call stack and the JavaScript code execution is complete. (Finally…)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Call stack

    |                    | ----------&amp;gt; GEC is popped out
    ----------------------

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Understanding execution context is the foundation for mastering hoisting, closures, scope, and asynchronous JavaScript. Once this mental model clicks, everything else becomes easier.&lt;/p&gt;

&lt;p&gt;Happy coding. Cheers!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>100daysofcode</category>
      <category>javascript</category>
    </item>
    <item>
      <title>4 Practical Applications of Closures in JavaScript</title>
      <dc:creator>Della Dominic</dc:creator>
      <pubDate>Tue, 17 Feb 2026 18:01:36 +0000</pubDate>
      <link>https://dev.to/della_codes/4-practical-applications-of-closures-in-javascript-1lkp</link>
      <guid>https://dev.to/della_codes/4-practical-applications-of-closures-in-javascript-1lkp</guid>
      <description>&lt;p&gt;When I first learned about closures, I thought they were rarely used and that I probably wouldn’t come across them often. What I didn’t realise then was that every time a function is created, a closure is formed automatically, because a function maintains a reference to its lexical environment.&lt;/p&gt;

&lt;p&gt;Closures are not just a theoretical concept. They are everywhere in our codebase, and they have powerful real-world use cases. Understanding these use cases, I believe, is crucial to truly understanding closures.&lt;/p&gt;

&lt;p&gt;Let’s look at four powerful applications of closures.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Data Privacy &amp;amp; Encapsulation
&lt;/h2&gt;

&lt;p&gt;Closures help you create private variables in JavaScript, preventing accidental modifications and protecting internal state.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fywl2r3tbiimhqdlwzcz8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fywl2r3tbiimhqdlwzcz8.png" alt="Image1" width="800" height="841"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Function Factories
&lt;/h2&gt;

&lt;p&gt;Closures make it possible to build tailored functions on demand. This pattern works especially well with the Fetch API, where you can create reusable and pre-configured API clients.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbjpm89r7m67xiqxh4wlp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbjpm89r7m67xiqxh4wlp.png" alt="Image2" width="800" height="548"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Preserving State in Callbacks &amp;amp; Event Handlers
&lt;/h2&gt;

&lt;p&gt;Closures are crucial for managing state in asynchronous operations. When you use addEventListener() to register an event handler, the callback retains access to variables from its outer scope.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwu2bfiqtjkn5k8fqrqxs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwu2bfiqtjkn5k8fqrqxs.png" alt="Image3" width="800" height="454"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Memoization (Caching Results)
&lt;/h2&gt;

&lt;p&gt;Closures can be used to memoize expensive operations by caching previous results. This improves performance by avoiding repeated calculations.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7f3a2854pnzav9eiy488.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7f3a2854pnzav9eiy488.png" alt="Image4" width="800" height="1056"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What once felt like an abstract concept turned out to be one of the most practical tools in JavaScript. The real power of closures isn’t in their definition — it’s in how often and how effectively we use them.&lt;/p&gt;

&lt;p&gt;Happy Learning!✨&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>100daysofcode</category>
      <category>webdev</category>
    </item>
    <item>
      <title>The split personality of the + operator</title>
      <dc:creator>Della Dominic</dc:creator>
      <pubDate>Mon, 16 Feb 2026 09:29:49 +0000</pubDate>
      <link>https://dev.to/della_codes/the-split-personality-of-the-operator-1hlb</link>
      <guid>https://dev.to/della_codes/the-split-personality-of-the-operator-1hlb</guid>
      <description>&lt;p&gt;Type coercion can be confusing if not well understood. Let's see how JavaScript converts (or coerces) around the + operator.&lt;/p&gt;

&lt;h2&gt;
  
  
  The split personality
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq65pvcb3clv15c82nsd4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq65pvcb3clv15c82nsd4.png" alt="image 1" width="800" height="178"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Why do we get string the first time and a number the second time when in both case we are trying to do mathematical operations?&lt;/p&gt;

&lt;p&gt;Well, JavaScript does not just do math, it looks at its operands and decides what needs to be done. So if we have just numbers like &lt;code&gt;5 + 3 // 8&lt;/code&gt; then it's pretty straightforward, however if at least one operand is a string along with the + operator, then the number is converted to string and string concatenation is what JavaScript will do. It will convert the number &lt;code&gt;2&lt;/code&gt; in the above example to string&lt;code&gt;"2"&lt;/code&gt; and then performs &lt;code&gt;"5" + "2"&lt;/code&gt; to give &lt;code&gt;"52"&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;What about the second operation? here, JavaScript converts the string to number and performs a mathematical operation and returns &lt;code&gt;2&lt;/code&gt;. When we use mathematical operators, JavaScript performs arithmetic. However, if the + operator has at least one string operand, it performs string concatenation. Otherwise, it performs arithmetic.&lt;/p&gt;

&lt;h2&gt;
  
  
  Order matters!
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsjzki8a0bfekq4im6ppz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsjzki8a0bfekq4im6ppz.png" alt="order matter" width="660" height="186"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;JavaScript evaluates your operation from left to right. Hence if you do &lt;code&gt;1 + 2 + '3'&lt;/code&gt; first &lt;code&gt;1 + 2&lt;/code&gt; is calculated resulting in &lt;code&gt;3&lt;/code&gt;. Then it evaluates &lt;code&gt;3 + '3'&lt;/code&gt;, where we are adding the number &lt;code&gt;3&lt;/code&gt; to the string &lt;code&gt;'3'&lt;/code&gt;. Therefore the numbers get implicitly converted to string and gets concatenated with the other string to give &lt;code&gt;'33'&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Notice in the second scenario we have the string first. &lt;code&gt;'1' + 2 + 3&lt;/code&gt; becomes &lt;code&gt;'12' + 3&lt;/code&gt; which returns &lt;code&gt;'123'&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  BaNaNa?!
&lt;/h2&gt;

&lt;p&gt;Let's see another interesting example.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4dh51xadrhoh4boouhc1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4dh51xadrhoh4boouhc1.png" alt="Image 2" width="466" height="94"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Why does &lt;code&gt;"Ba" + + "test" +"a"&lt;/code&gt; evaluate to &lt;code&gt;'BaNaNa'&lt;/code&gt;? Let's break this down. Here we are trying to concatenate &lt;code&gt;"Ba"&lt;/code&gt; with &lt;code&gt;+"test"&lt;/code&gt;. Adding the unary plus operator to string (&lt;code&gt;+"a string"&lt;/code&gt;) is one way you can explicitly convert a string to a number (the unary plus trick). So &lt;code&gt;+"test"&lt;/code&gt; becomes &lt;code&gt;NaN&lt;/code&gt;, resulting in &lt;code&gt;"Ba" + "NaN" + "a"&lt;/code&gt; giving you &lt;code&gt;"BaNaNa"&lt;/code&gt;🍌!&lt;/p&gt;

&lt;p&gt;To recap, the + operator in JavaScript is overloaded — its behavior depends entirely on the types of its operands.&lt;/p&gt;

&lt;p&gt;Understand the types, and you understand the result.&lt;/p&gt;

&lt;p&gt;Happy learning! ✨&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>100daysofcode</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Call by sharing: Understanding why JavaScript does NOT pass objects By Reference</title>
      <dc:creator>Della Dominic</dc:creator>
      <pubDate>Sun, 15 Feb 2026 12:21:59 +0000</pubDate>
      <link>https://dev.to/della_codes/call-by-sharing-understanding-why-javascript-does-not-pass-objects-by-reference-1npk</link>
      <guid>https://dev.to/della_codes/call-by-sharing-understanding-why-javascript-does-not-pass-objects-by-reference-1npk</guid>
      <description>&lt;p&gt;For a long time I thought primitive types are shared by value and objects are shared by reference in javascript. Today I learned however that javascript always pass by value (According to the ECMAScript specification), both primitive types and objects. However when passing objects the value that is being passed is the reference.This behaviour is known as 'call by sharing' and NOT pass by reference. let's see why...&lt;/p&gt;

&lt;h2&gt;
  
  
  Call by Sharing: How JavaScript Passes Objects
&lt;/h2&gt;

&lt;p&gt;Let's first see how &lt;strong&gt;primitive values&lt;/strong&gt; are passed.&lt;/p&gt;

&lt;p&gt;Consider the below code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function setName(copyOfName){
    copyOfName = "John";
}

let name ="Della";
setName(name);
console.log(name);// "Della"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's pretty straightforward and easy to understand why primitive types are passed by value. Here we are passing the argument, 'name' that is assigned to the parameter, 'copyOfName'. That is, copyOfName now contains a copy of the variable, name, which has the value "Della". and reassigning copyOfName to "John" only affect this copy not the original name variable.&lt;/p&gt;

&lt;p&gt;Now what if we were passing an &lt;strong&gt;object&lt;/strong&gt;?&lt;/p&gt;

&lt;p&gt;consider the below code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function setPerson(copyOfPerson){
    copyOfPerson.name = "John"; // here we are MUTATING
}

let person = {
    name: "Della",
}
setPerson(person);
console.log(person); // { name: "John" }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we have an object person with name as "Della" which we are passing to the function's parameter, copyOfPerson by pass by value. But the value passed here is a copy of the reference. Hence both copyOfPerson and name point to the same object. Therefore, any modification or mutation (NOTE, I am mutating the object NOT re-assigning! - Big Difference) to the copy affects the original object since both point to the same object. That is why person becomes &lt;code&gt;{ name: "John" }&lt;/code&gt; when copyOfPerson is modified.&lt;/p&gt;

&lt;p&gt;Now you might ask - isn't this what is known as 'Pass by Reference' ?!&lt;/p&gt;

&lt;p&gt;Well...not really. The above code works the way it works fundamentally because an object variable contains a reference value.That reference value is itself the value stored in the variable. So technically, the reference is the value! And that's why we say javascript passes reference by value.&lt;/p&gt;

&lt;p&gt;To prove programmatically, let's consider the below code, where we try to 're-assign' the copy.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function setPerson(copyOfPerson){
    copyOfPerson = {
        name: "John",
    }// here we are RE-ASSIGNING
}

let person = {
    name: "Della",
}
setPerson(person);
console.log(person); // { name: "Della" }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the object was truly passed by reference, even reassigning would change the original object. However that is not the case. Here, local rebinding happens. a new object is created and it's reference is assigned to copyOfPerson. Therefore it no longer points to person and that is why person remains same ,&lt;code&gt;{ name: "Della" }&lt;/code&gt;. This is called 'call by sharing' also known as 'call by object sharing'&lt;/p&gt;

&lt;p&gt;To recap, JavaScript is a pass-by-value language. However, when passing objects, the value being passed is the reference to the object. This behaviour is known as call-by-sharing. In call-by-sharing, when an object is passed to a function, a copy of the reference is created and thus objects are shared. However, variable binding is not shared. So mutating the parameter modifies the original object but reassigning the parameter does not affect the original object.&lt;/p&gt;

&lt;p&gt;Happy learning! cheers ✨&lt;/p&gt;

</description>
      <category>100daysofcode</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Why does 0.1 + 0.2 === 0.3 return false?</title>
      <dc:creator>Della Dominic</dc:creator>
      <pubDate>Fri, 13 Feb 2026 14:07:05 +0000</pubDate>
      <link>https://dev.to/della_codes/why-does-01-02-03-return-false-3nhl</link>
      <guid>https://dev.to/della_codes/why-does-01-02-03-return-false-3nhl</guid>
      <description>&lt;p&gt;Javascript uses IEEE 754 floating point representation for storing numbers. This means that some decimal fractions (like 0.1) cannot be represented exactly in binary floating-point format.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7ggrtqakmez0vxagae8s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7ggrtqakmez0vxagae8s.png" alt="decimals not matching" width="710" height="196"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So how DO we work with decimals?&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Compare with tolerance for equality checks
&lt;/h2&gt;

&lt;p&gt;Taking into consideration the small error difference, Instead of comparing 2 decimals with equality operator we will check if the difference between them is less than the tolerance value.&lt;/p&gt;

&lt;p&gt;Javascript provides a static property, Number.EPSILON that represents the smallest difference. Using this we can compare the equality of decimals as shown below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F10ilteqkmpr1efr3t3dy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F10ilteqkmpr1efr3t3dy.png" alt="using tolerance to compare decimals" width="800" height="223"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: Number.EPSILON works well when numbers are around magnitude 1, but for larger numbers we might scale EPSILON accordingly.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftlne4kl5edbybv6end9q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftlne4kl5edbybv6end9q.png" alt="scale epsilon value" width="800" height="315"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Working with Money?
&lt;/h2&gt;

&lt;p&gt;Avoid floating-point arithmetic for financial calculations. Use integers (cents/paise) or dedicated decimal libraries. Always convert to cents, not dollars. This is Recommended in terms of working with billing or payment logic in Fintech Apps.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg9wme6trrhuzoat2eyvj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg9wme6trrhuzoat2eyvj.png" alt="work with cents" width="800" height="136"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Use Intl.NumberFormat for display
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fluvjiha6kmf74465vh3i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fluvjiha6kmf74465vh3i.png" alt="format using intl.numberformat" width="800" height="334"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Use toFixed() for simple rounding
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv3b5b3ywum6zrmudb7y1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv3b5b3ywum6zrmudb7y1.png" alt="using toFixed" width="580" height="88"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: Can you think what would be the output of below code?&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;console.log((0.1 + 0.2).toFixed(2) === 0.30);&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
 This will return false since toFixed() returns a string not a number and hence the strict equality check fails!&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvsmbo7tsvrakfpuzmkck.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvsmbo7tsvrakfpuzmkck.png" alt="to.Fixed return string" width="742" height="178"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;you can read more about it here - &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/EPSILON" rel="noopener noreferrer"&gt;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/EPSILON&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Happy learning! cheers✨&lt;/p&gt;

</description>
      <category>100daysofcode</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
