<?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: Arokiya Kithiyon</title>
    <description>The latest articles on DEV Community by Arokiya Kithiyon (@arokiya_kithiyon_1f2bad36).</description>
    <link>https://dev.to/arokiya_kithiyon_1f2bad36</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%2F3257812%2F5f8a77de-59f4-4f22-9c30-1c5299ecce1b.jpg</url>
      <title>DEV Community: Arokiya Kithiyon</title>
      <link>https://dev.to/arokiya_kithiyon_1f2bad36</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/arokiya_kithiyon_1f2bad36"/>
    <language>en</language>
    <item>
      <title>Elements in HTML</title>
      <dc:creator>Arokiya Kithiyon</dc:creator>
      <pubDate>Tue, 17 Feb 2026 13:51:17 +0000</pubDate>
      <link>https://dev.to/arokiya_kithiyon_1f2bad36/elements-in-html-29ag</link>
      <guid>https://dev.to/arokiya_kithiyon_1f2bad36/elements-in-html-29ag</guid>
      <description>&lt;p&gt;HTML (HyperText Markup Language) is the standard language used to create and structure web pages, acting as the foundational building block of the internet. It uses a system of tags and elements to define content types like headings, paragraphs, and links, allowing browsers to render text, images, and multimedi&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Event bubbling and Capturing in Java script</title>
      <dc:creator>Arokiya Kithiyon</dc:creator>
      <pubDate>Fri, 17 Oct 2025 02:18:53 +0000</pubDate>
      <link>https://dev.to/arokiya_kithiyon_1f2bad36/event-bubbling-and-propagation-in-java-script-h2n</link>
      <guid>https://dev.to/arokiya_kithiyon_1f2bad36/event-bubbling-and-propagation-in-java-script-h2n</guid>
      <description>&lt;p&gt;&lt;strong&gt;What is Event Bubbling?&lt;/strong&gt;&lt;br&gt;
Event bubbling in JavaScript is a mechanism in the Document Object Model (DOM) where an event, triggered on a specific element, propagates upwards through its parent elements in the DOM hierarchy.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;body&amp;gt;
  &amp;lt;div&amp;gt;
      &amp;lt;button&amp;gt;Click Me!&amp;lt;/button&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;The button is a child of the span, which in turn is a child of the div, and the div is a child of the body. &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%2Fqlli4iry52xd9lp92i19.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%2Fqlli4iry52xd9lp92i19.png" alt=" " width="361" height="348"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;element&amp;gt;.addEventListener(&amp;lt;eventName&amp;gt;, 
    &amp;lt;callbackFunction&amp;gt;, {capture : boolean});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;element: The element to which an event listener is attached.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;eventName: It can be 'click','key up','key down' etc. events.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;callbackFunction: This function fires after the event happened.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;{capture: boolean}: It tells whether the event will be in the capture phase or in the bubbling phase (optional)&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;body&amp;gt;
    &amp;lt;div&amp;gt;
        &amp;lt;h2&amp;gt;Welcome To Kithi's DEV Community&amp;lt;/h2&amp;gt;
        &amp;lt;div id="grandparent"&amp;gt;GrandParent
            &amp;lt;div id="parent"&amp;gt;Parent
                &amp;lt;div id="child"&amp;gt;Child&amp;lt;/div&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;

 &amp;lt;script&amp;gt;
        const grandParent = document.getElementById("grandparent");
        const parent = document.getElementById("parent");
        const child = document.getElementById("child");

        grandParent.addEventListener("click", (e) =&amp;gt; {
            console.log("GrandParent");
        }, { capture: false });
        parent.addEventListener("click", (e) =&amp;gt; {
            console.log("Parent");
        }, { capture: false });
        child.addEventListener("click", (e) =&amp;gt; {
            console.log("Child");
        }, { capture: false });
    &amp;lt;/script&amp;gt;

&amp;lt;/body&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Child&lt;br&gt;
Parent&lt;br&gt;
GrandParent&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;When we clicked on the div with the child as its id, we should get the output as 'child' on our console. But unexpectedly, we are receiving a different output even we have not clicked on divs with parent and grandparent as their id. The concept of event bubbling comes into the picture. The child div lies inside the parent div as well as in the grandparent div. So, when the child div clicked, we indirectly clicked on both parent div and grandparent div. Thus, propagation is moving from inside to outside in the DOM or we can say events are getting bubble up. &lt;/p&gt;

&lt;p&gt;Therefore, the process of propagating from the closest element to the farthest away element in the DOM (Document Object Modal) is called event bubbling.&lt;/p&gt;

&lt;p&gt;In the above example, let us change the value of the third parameter of addEventListener() and see what changes will be made in the output.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;body&amp;gt;
    &amp;lt;div&amp;gt;
        &amp;lt;h2&amp;gt;Welcome To Kithi's DEV Community&amp;lt;/h2&amp;gt;
        &amp;lt;div id="grandparent"&amp;gt;GrandParent
            &amp;lt;div id="parent"&amp;gt;Parent
                &amp;lt;div id="child"&amp;gt; Child&amp;lt;/div&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;script&amp;gt;
        const grandParent = document.getElementById("grandparent");
        const parent = document.getElementById("parent");
        const child = document.getElementById("child");

        // Changing value of capture parameter as 'true'
        grandParent.addEventListener("click", (e) =&amp;gt; {
            console.log("GrandParent");
        }, { capture: true });
        parent.addEventListener("click", (e) =&amp;gt; {
            console.log("Parent");
        }, { capture: true });
        child.addEventListener("click", (e) =&amp;gt; {
            console.log("Child");
        }, { capture: true });
    &amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;GrandParent&lt;br&gt;
Parent&lt;br&gt;
Child&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It's clearly visible that the ancestor divs of the child div were printing first and then the child div itself. So, the process of propagating from the farthest element to the closest element in the DOM is called event capturing. Both terms are just opposite of each other.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to stop event bubbling and event capturing?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the above example, we can see a parameter "e" (or sometimes called as "event") in the callback function of addEventListener(). It is an event object which automatically defines when we add an event listener to an element. This object 'e' has a function called stopPropagation() which helps to prevent this annoying behavior.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;body&amp;gt;
    &amp;lt;div&amp;gt;
        &amp;lt;h2&amp;gt;Welcome To Kithi's DEV Community&amp;lt;/h2&amp;gt;
        &amp;lt;div id="grandparent"&amp;gt;GrandParent
            &amp;lt;div id="parent"&amp;gt;Parent
                &amp;lt;div id="child"&amp;gt; Child&amp;lt;/div&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;

    &amp;lt;script&amp;gt;
        const grandParent = document.getElementById("grandparent");
        const parent = document.getElementById("parent");
        const child = document.getElementById("child");
        grandParent.addEventListener("click", (e) =&amp;gt; {
            console.log("GrandParent bubbling");
        });
        parent.addEventListener("click", (e) =&amp;gt; {
            e.stopPropagation();  //syntax to stop event bubbling
            console.log("Parent bubbling");
        });
        child.addEventListener("click", (e) =&amp;gt; {
            console.log("Child bubbling");
        });
    &amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Child bubbling&lt;br&gt;
Parent bubbling&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;if we clicked on child div, the propagation is stopped on parent div and does not move to grandparent div. Hence, the event bubbling is prevented. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt;&lt;br&gt;
The event capturing can also be prevented using the same way.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Event capturing means propagation of event is done from ancestor elements to child element in the DOM while event bubbling means propagation is done from child element to ancestor elements in the DOM.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The event capturing occurs followed by event bubbling.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If {capture: true} ,event capturing will occur else event bubbling will occur.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Both can be prevented by using the stopPropagation() method.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>evenbubbling</category>
      <category>eventpropagation</category>
      <category>kithiyon</category>
    </item>
    <item>
      <title>Event loop in Javascript</title>
      <dc:creator>Arokiya Kithiyon</dc:creator>
      <pubDate>Sat, 11 Oct 2025 17:51:34 +0000</pubDate>
      <link>https://dev.to/arokiya_kithiyon_1f2bad36/event-loop-in-javascript-3dhc</link>
      <guid>https://dev.to/arokiya_kithiyon_1f2bad36/event-loop-in-javascript-3dhc</guid>
      <description>&lt;p&gt;&lt;strong&gt;What is the Event Loop?&lt;/strong&gt;&lt;br&gt;
At its core, the JavaScript event loop is responsible for managing the execution of code, collecting and processing events, and executing queued tasks. JavaScript operates in a single-threaded environment, meaning only one piece of code runs at a time. The event loop ensures that tasks are executed in the correct order, enabling asynchronous programming.&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%2F5625zkq0zhmak1m3fwk9.gif" 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%2F5625zkq0zhmak1m3fwk9.gif" alt=" " width="760" height="427"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Call stack&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Call stack keeps track of the functions being executed in a program. When a function is called, it is added to the top of the call stack. When the function completes, it is removed from the call stack. This allows the program to keep track of where it is in the execution of a function and return to the correct location when the function completes. As the name suggests it is a Stack data structure which follows last-in-first-out.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Web APIs/Node.js APIs&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Asynchronous operations like setTimeout(), HTTP requests, file I/O, etc., are handled by Web APIs (in the browser) or C++ APIs (in Node.js). These APIs are not part of the JavaScript engine and run on separate threads, allowing them to execute concurrently without blocking the call stack.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task queue / Macrotask queue / Callback queue&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The task queue, also known as the macrotask queue / callback queue / event queue, is a queue that holds tasks that need to be executed. These tasks are typically asynchronous operations, such as callbacks passed to web APIs (setTimeout(), setInterval(), HTTP requests, etc.), and user interface event handlers like clicks, scrolls, etc.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Microtasks queue&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Microtasks are tasks that have a higher priority than macrotasks and are executed immediately after the currently executing script is completed and before the next macrotask is executed. Microtasks are usually used for more immediate, lightweight operations that should be executed as soon as possible after the current operation completes. There is a dedicated microtask queue for microtasks. Microtasks include promises callbacks (then(), catch(), and finally()), await statements, queueMicrotask(), and MutationObserver callbacks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example of the Event Loop in Action&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log("Start");

setTimeout(() =&amp;gt; {
    console.log("Timeout Callback");
}, 0);

Promise.resolve().then(() =&amp;gt; {
    console.log("Promise Resolved");
});

console.log("End");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;br&gt;
Start&lt;br&gt;
End&lt;br&gt;
Promise Resolved&lt;br&gt;
Timeout Callback&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;console.log("Start") executes first.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;setTimeout is encountered, and its callback is delegated to the Web API (it won’t execute immediately).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A resolved promise is pushed to the Microtask Queue.&lt;br&gt;
console.log("End") executes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Since the Call Stack is empty, the Event Loop processes the Microtask Queue first, executing Promise Resolved.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Finally, the callback from setTimeout is executed from the Callback Queue.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The event loop is a core mechanism in JavaScript that allows the single-threaded language to handle asynchronous tasks without blocking the main thread. It works in conjunction with the call stack, which processes synchronous code, and the event queue, where asynchronous tasks wait to be executed. As JavaScript runs, the event loop continuously monitors the call stack, only processing tasks from the event queue when the stack is empty. This system enables efficient handling of I/O operations, user interactions, and background tasks, allowing JavaScript to run smoothly and responsively despite its single-threaded nature.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>eventloopinjavascript</category>
      <category>eventloop</category>
      <category>kithiyon</category>
    </item>
    <item>
      <title>"this" Key word in java script</title>
      <dc:creator>Arokiya Kithiyon</dc:creator>
      <pubDate>Sun, 05 Oct 2025 14:43:43 +0000</pubDate>
      <link>https://dev.to/arokiya_kithiyon_1f2bad36/this-key-word-in-java-script-gda</link>
      <guid>https://dev.to/arokiya_kithiyon_1f2bad36/this-key-word-in-java-script-gda</guid>
      <description>&lt;p&gt;The this keyword in JavaScript is a special keyword that refers to the context in which a function is executed. Its value is not determined by where the function is defined, but by how it is called (its "call site"). This dynamic nature can make this a challenging concept to grasp initially.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Global Context:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Outside of any function or object, in a browser environment, this refers to the global window object.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In Node.js, this in the global scope refers to the globalThis object.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In strict mode, this in the global context is undefined.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Method Invocation:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When a function is called as a method of an object (e.g., object.method()), this refers to the object on which the method was called.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    const person = {
        name: "Alice",
        greet: function() {
            console.log(`Hello, my name is ${this.name}`);
        }
    };
    person.greet(); // 'this' refers to 'person'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Function Invocation (Standalone):&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;When a function is called as a standalone function (not as a method of an object), this typically refers to the global object (window in browsers, globalThis in Node.js) in non-strict mode. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In strict mode, this is undefined in a standalone function call.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    function sayHello() {
        console.log(this); // In a browser, 'this' would be 'window' (non-strict)
    }
    sayHello();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Arrow Functions:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Arrow functions do not have their own this binding. Instead, they lexically inherit this from their surrounding (enclosing) scope at the time they are defined. This makes them particularly useful for callbacks where preserving the context of this is important.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    const anotherPerson = {
        name: "Charlie",
        greet: function() {
            setTimeout(() =&amp;gt; {
                console.log(`Hello, my name is ${this.name}`); // 'this' correctly refers to 'anotherPerson'
            }, 100);
        }
    };
    anotherPerson.greet();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explicit Binding with call, apply, and bind&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Explicit binding in JavaScript refers to the process of explicitly setting the value of the this keyword within a function's execution context. This is achieved using the call(), apply(), and bind() methods available on all JavaScript functions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;call():&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Invokes a function immediately.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The first argument passed to call() becomes the this value inside the function.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Subsequent arguments are passed directly to the function as individual arguments.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    function greet(greeting) {
      console.log(`${greeting}, my name is ${this.name}`);
    }

    const person = { name: "Alice" };
    greet.call(person, "Hello"); // Output: Hello, my name is Alice
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;apply():&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Similar to call(), it invokes a function immediately.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The first argument passed to apply() becomes the this value.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Subsequent arguments are passed to the function as an array.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    function sum(a, b) {
      console.log(`The sum is ${this.multiplier * (a + b)}`);
    }

    const context = { multiplier: 2 };
    sum.apply(context, [5, 3]); // Output: The sum is 16
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;bind():&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Unlike call() and apply(), bind() does not immediately invoke the function.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It returns a new function with this permanently bound to the specified object. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Any arguments passed to bind() after the this context are prepended to the new function's arguments.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    const user = { name: "Bob" };

    function sayName() {
      console.log(`My name is ${this.name}`);
    }

    const boundSayName = sayName.bind(user);
    boundSayName(); // Output: My name is Bob
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The this keyword in JavaScript is a versatile and powerful feature that, when understood correctly, can greatly enhance your coding capabilities. &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>thiskeyword</category>
      <category>thiskeywordinjavascript</category>
      <category>kithiyon</category>
    </item>
    <item>
      <title>Closures in Javascript</title>
      <dc:creator>Arokiya Kithiyon</dc:creator>
      <pubDate>Sat, 04 Oct 2025 03:57:08 +0000</pubDate>
      <link>https://dev.to/arokiya_kithiyon_1f2bad36/closures-in-javascript-1nmb</link>
      <guid>https://dev.to/arokiya_kithiyon_1f2bad36/closures-in-javascript-1nmb</guid>
      <description>&lt;p&gt;In JavaScript, a closure is the combination of a function and the lexical environment within which that function was declared. This means that an inner function "remembers" and can access the variables and arguments of its outer (enclosing) function, even after the outer function has finished executing and its execution context has been removed from the call stack.&lt;/p&gt;

&lt;p&gt;Another way to think about it — and likely a picture you won’t forget — is to think of closures as a pregnant woman and her unborn baby. Once the baby is born, it still has access to its mom’s DNA even though it is no longer inside the womb. Similarly, a nested function in a closure still has access to its lexical scope, or environment, even after the parent function has finished executing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key characteristics of closures:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lexical Scoping:&lt;/strong&gt;&lt;br&gt;
JavaScript uses lexical scoping, meaning that the scope of a variable is determined by where it is written in the code, not where it is called. A closure captures this lexical environment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Data Privacy:&lt;/strong&gt;&lt;br&gt;
Closures allow for the creation of private variables and methods, as the inner function can access variables from its outer scope, while those variables are not directly accessible from the global scope. This is a powerful mechanism for data encapsulation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Persistence of State:&lt;/strong&gt;&lt;br&gt;
Even after the outer function has returned, the inner function retains access to the outer function's variables, allowing the state of those variables to persist across multiple calls to the inner function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function createCounter() {
  let count = 0; // This variable is part of the lexical environment

  return function() { // This is the inner function (the closure)
    count++;
    return count;
  };
}

const counter1 = createCounter();
console.log(counter1()); // Output: 1
console.log(counter1()); // Output: 2

const counter2 = createCounter(); // Creates a new closure with its own 'count'
console.log(counter2()); // Output: 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, createCounter returns an anonymous inner function. This inner function forms a closure over the count variable declared in createCounter. Each time counter1() is called, it increments its own count variable, which persists between calls. counter2 creates a separate closure with its own independent count.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>closures</category>
      <category>kithiyon</category>
      <category>closuresinjavascript</category>
    </item>
    <item>
      <title>Hoisting In Javascript</title>
      <dc:creator>Arokiya Kithiyon</dc:creator>
      <pubDate>Fri, 26 Sep 2025 19:21:02 +0000</pubDate>
      <link>https://dev.to/arokiya_kithiyon_1f2bad36/hoisting-javascript-a0d</link>
      <guid>https://dev.to/arokiya_kithiyon_1f2bad36/hoisting-javascript-a0d</guid>
      <description>&lt;p&gt;Hoisting in JavaScript is a mechanism where variable and function declarations are moved to the top of their containing scope during the compilation phase, before the code is executed. This means you can use variables and call functions before they are explicitly declared in your code&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here's how hoisting works for different types of declarations:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;var declarations:&lt;/strong&gt; Variables declared with &lt;code&gt;var&lt;/code&gt; are hoisted to the top of their scope and are initialized with undefined. This means you can access a var variable before its declaration, but its value will be undefined until the line of code where it's assigned a value is executed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    console.log(myVar); // Output: undefined
    var myVar = 10;
    console.log(myVar); // Output: 10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Hoisting &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; variables&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Variables declared with &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; are also hoisted, but they are not initialized. Instead, they enter a "Temporal Dead Zone" (TDZ) from the beginning of their scope until their declaration line is reached. Attempting to access a let or const variable within the TDZ will result in a &lt;code&gt;ReferenceError&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    // console.log(myLet); // This would throw a ReferenceError (TDZ)
    let myLet = 20;
    console.log(myLet); // Output: 20
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The Temporal Dead Zone in JavaScript&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The Temporal Dead Zone (TDZ) is a critical concept in JavaScript hoisting. It refers to the period between the entering of a scope (such as a function or block) and the actual initialization of a variable declared with &lt;code&gt;let&lt;/code&gt; or &lt;code&gt;const&lt;/code&gt;. During this time, any reference to the variable before its initialization will throw a ReferenceError.&lt;/p&gt;

&lt;p&gt;How does the TDZ Work?&lt;/p&gt;

&lt;p&gt;Variables declared with &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; are hoisted to the top of their scope, but they are not initialized until their declaration line is reached.&lt;br&gt;
    Any attempt to access these variables before their declaration will result in an error.&lt;br&gt;
    The TDZ exists only for variables declared using &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt;. Variables declared with &lt;code&gt;var&lt;/code&gt; do not have this issue, as they are hoisted and initialized to &lt;code&gt;undefined&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(myName) // temporal dead zone for myName,  
//ReferenceError: Cannot access 'myName' before initialization
// temporal dead zone for myName
// temporal dead zone for myName
// temporal dead zone for myName
// temporal dead zone for myName
// temporal dead zone for myName
// temporal dead zone for myName
let myName = "Kithiyon" // now accessible
// now accessible
// now accessible
// now accessible
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Function declarations:&lt;/strong&gt; Function declarations are fully hoisted, meaning both the function name and its definition are moved to the top of their scope. This allows you to call a function before its declaration in the 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 printHello() {
  console.log("hello")
}

printHello()
// hello

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

&lt;/div&gt;



&lt;p&gt;Here, we declare printHello, and we execute the function just after the line it was declared. No errors; everything works!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;printHello()
// hello

function printHello() {
  console.log("hello")
}

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

&lt;/div&gt;



&lt;p&gt;Here, we execute printHello before the line the function was declared. And everything still works without errors. What happened here? Hoisting.&lt;/p&gt;

&lt;p&gt;Before the interpreter executes the whole code, it first hoists (raises, or lifts) the declared function to the top of the scope it is defined in. In this case, printHello is defined in the global scope, so the function is hoisted to the top of the global scope. Through hoisting, the function (including the logic) becomes accessible even before the line it was declared in the code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Function expressions and arrow functions:&lt;/strong&gt; &lt;br&gt;
These are treated like variable declarations. If declared with var, they will be hoisted and initialized to undefined. If declared with let or const, they will be in the TDZ.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    // myFuncExpression(); // This would throw a TypeError if declared with var (undefined is not a function)
    // myArrowFunc(); // This would throw a ReferenceError if declared with let/const (TDZ)

    var myFuncExpression = function() {
      console.log("Hello from function expression!");
    };
    myFuncExpression(); // Output: Hello from function expression!

    const myArrowFunc = () =&amp;gt; {
      console.log("Hello from arrow function!");
    };
    myArrowFunc(); // Output: Hello from arrow function!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In summary, while hoisting moves declarations to the top, the initialization behavior differs between &lt;code&gt;var&lt;/code&gt; and &lt;code&gt;let/const&lt;/code&gt;, and &lt;code&gt;function&lt;/code&gt; declarations are fully hoisted, enabling early invocation. Understanding hoisting is crucial for writing predictable and error-free JavaScript code.&lt;/p&gt;

</description>
      <category>hoisting</category>
      <category>javascript</category>
      <category>payilagam</category>
      <category>kithiyon</category>
    </item>
    <item>
      <title>Execution Context in JavaScript</title>
      <dc:creator>Arokiya Kithiyon</dc:creator>
      <pubDate>Thu, 25 Sep 2025 17:15:41 +0000</pubDate>
      <link>https://dev.to/arokiya_kithiyon_1f2bad36/execution-context-in-javascript-4337</link>
      <guid>https://dev.to/arokiya_kithiyon_1f2bad36/execution-context-in-javascript-4337</guid>
      <description>&lt;p&gt;An execution context is&lt;br&gt;
the environment in which JavaScript code is executed. Everything that happens in JavaScript occurs inside an execution context, which manages the code's variables, functions, and scope.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The two phases of an execution context&lt;/em&gt;&lt;br&gt;
Every execution context is created and processed in two distinct phases: &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Creation phase:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Variable object creation: The JavaScript engine scans the code and stores function declarations and variables in memory. For var variables, it assigns the placeholder value undefined. This behavior is known as hoisting.&lt;/li&gt;
&lt;li&gt;        Scope chain setup: The engine establishes the scope chain, which determines where variables can be accessed. A function can access variables from its own context and the contexts of its parent functions, all the way up to the global scope.&lt;/li&gt;
&lt;li&gt;        &lt;strong&gt;this&lt;/strong&gt; keyword assignment: The this keyword is assigned a value depending on how the code was called.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Execution phase:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The JavaScript engine runs the code line by line.&lt;/li&gt;
&lt;li&gt;        It assigns the actual values to the variables that were initially set to undefined during the creation phase.&lt;/li&gt;
&lt;li&gt;        It invokes functions and executes the statements in the script.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Types of execution contexts&lt;/strong&gt;&lt;br&gt;
There are two main types of execution contexts: &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Global Execution Context (GEC):&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The default context where code is executed. For every JavaScript file, there is only one GEC.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It creates a global object (window in browsers or global in Node.js) and binds the this keyword to it. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;All global variables and functions are stored as properties and methods on this global object.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Function Execution Context (FEC):&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Created every time a function is called.&lt;/li&gt;
&lt;li&gt;Unlike the GEC, there can be many FECs in a program.
&lt;/li&gt;
&lt;li&gt;It creates its own scope for variables and a special arguments object containing all arguments passed to the function.&lt;/li&gt;
&lt;li&gt;Once a function's execution is complete, its context is destroyed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;The Call Stack&lt;/strong&gt;&lt;br&gt;
The JavaScript engine uses a call stack to manage all the execution contexts. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;   It operates on a Last-In, First-Out (LIFO) basis.&lt;/li&gt;
&lt;li&gt;    When a script is first run, the GEC is pushed onto the stack.&lt;/li&gt;
&lt;li&gt;    Whenever a function is invoked, its FEC is created and pushed onto the top of the stack, becoming the currently active context.&lt;/li&gt;
&lt;li&gt;    When a function finishes execution, its context is popped off the stack, and control returns to the context below it.&lt;/li&gt;
&lt;li&gt;    The program ends when the GEC is finally popped off the stack.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;function funcA(m,n) {&lt;br&gt;
    return m * n;&lt;br&gt;
}&lt;br&gt;
function funcB(m,n) {&lt;br&gt;
    return funcA(m,n);&lt;br&gt;
}&lt;br&gt;
function getResult(num1, num2) {&lt;br&gt;
    return funcB(num1, num2)&lt;br&gt;
}&lt;br&gt;
var res = getResult(5,6);&lt;br&gt;
console.log(res); // 30&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In this example, the JS engine creates a global execution context that enters the creation phase.&lt;/p&gt;

&lt;p&gt;First it allocates memory for funcA, funcB, the getResult function, and the res variable. Then it invokes getResult(), which will be pushed on the call stack.&lt;/p&gt;

&lt;p&gt;Then getResult() will call funcB(). At this point, funcB's context will be stored on the top of the stack. Then it will start executing and call another function funcA(). Similarly, funcA's context will be pushed.&lt;/p&gt;

&lt;p&gt;Once execution of each function is done, it will be removed from the call stack. The following picture depicts the entire process of the execution:&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%2Fp4h05c5eh8wntt8h3mwn.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%2Fp4h05c5eh8wntt8h3mwn.png" alt=" " width="800" height="231"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>interview</category>
      <category>programming</category>
      <category>payilagam</category>
    </item>
  </channel>
</rss>
