<?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>Forem: Roja Gnanavel</title>
    <description>The latest articles on Forem by Roja Gnanavel (@roja_gnanavel).</description>
    <link>https://forem.com/roja_gnanavel</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%2F2692083%2F93838f46-fcb1-47af-87a6-2d588097df9e.jpeg</url>
      <title>Forem: Roja Gnanavel</title>
      <link>https://forem.com/roja_gnanavel</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/roja_gnanavel"/>
    <language>en</language>
    <item>
      <title>Introduction to Polyfills: Making Old Browsers Smarter</title>
      <dc:creator>Roja Gnanavel</dc:creator>
      <pubDate>Mon, 07 Jul 2025 05:43:30 +0000</pubDate>
      <link>https://forem.com/jslovers/introduction-to-polyfills-making-old-browsers-smarter-o58</link>
      <guid>https://forem.com/jslovers/introduction-to-polyfills-making-old-browsers-smarter-o58</guid>
      <description>&lt;p&gt;Ever tried opening a cool new website on an old browser, and things just don’t work? That’s because older browsers don’t always understand the latest JavaScript features and that’s where polyfills come to the rescue.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is a Polyfill&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A polyfill is like a translator for old browsers. It helps them understand modern JavaScript features.&lt;/p&gt;

&lt;p&gt;🔹 Think of it as a friend explaining modern slang to your grandma.&lt;br&gt;
🔹 Without this explanation, she might not get what “vibe check” or “lit” means.&lt;br&gt;
🔹 Similarly, older browsers don’t understand new JavaScript features unless we help them out.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Do We Need Polyfills&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s say you’re building a website and using the fetch API to get data from the internet. Everything works fine on modern browsers like Chrome and Edge.&lt;/p&gt;

&lt;p&gt;But then, someone visits your site using Internet Explorer, and suddenly, your site breaks.&lt;/p&gt;

&lt;p&gt;Why? Because IE doesn’t know what fetch is and it’s not built in.&lt;/p&gt;

&lt;p&gt;This is where a polyfill comes in. It acts as a backup plan by adding support for fetch in older browsers, ensuring your code works everywhere.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How Polyfills Work Internally&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Some JavaScript features don’t exist in old browsers. Polyfills help by checking if a feature is available:&lt;/p&gt;

&lt;p&gt;✅ If the feature exists, the polyfill does nothing (because the browser already supports it).&lt;/p&gt;

&lt;p&gt;❌ If the feature doesn’t exist, the polyfill adds it using older JavaScript code that works in all browsers.&lt;/p&gt;

&lt;p&gt;This is called feature detection.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Understanding prototype (Before We Begin)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In JavaScript, objects like arrays, functions, and objects inherit properties from their prototype&lt;/p&gt;

&lt;p&gt;Still confused? Let’s make it simple.&lt;br&gt;
Think of prototype as a shared toolbox for JavaScript objects.&lt;/p&gt;

&lt;p&gt;Arrays, functions, and objects all come with a built-in toolbox.&lt;/p&gt;

&lt;p&gt;If we add a new tool (method) to Array.prototype, every array gets it automatically.&lt;/p&gt;

&lt;p&gt;📌 Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Array.prototype.sayHello = function () {
  console.log("Hello from an array!");
};

const fruits = ["apple", "banana"];
fruits.sayHello(); // 🟢 Output: Hello from an array!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔹 Even though we didn’t add sayHello() to fruits, it still works.&lt;br&gt;
🔹 That’s because all arrays share the same toolbox (Array.prototype).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why is prototype important for polyfills&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Polyfills add missing features to older browsers.&lt;br&gt;
Since prototype allows methods to be shared across all objects of a type, polyfills use it to ensure all arrays, objects, or functions can access the new feature.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Analogy&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Imagine a building with 100 apartments (arrays).&lt;/p&gt;

&lt;p&gt;If we install a water purifier at the main pipeline (prototype), all apartments get clean water.&lt;/p&gt;

&lt;p&gt;We don’t need to install a purifier in every single apartment.&lt;/p&gt;

&lt;p&gt;That’s exactly how polyfills work they add a missing feature at the prototype level so everything can use it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example: The includes() Method&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The includes() method for arrays was introduced in ES6 (2015).&lt;br&gt;
Older browsers (like Internet Explorer) don’t have it.&lt;/p&gt;

&lt;p&gt;So, let’s say you write this code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fruits = ["apple", "banana", "orange"];
console.log(fruits.includes("banana")); // 🟢 Works in modern browsers
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🚨 But in older browsers, this will throw an error because includes() doesn’t exist&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How Polyfills Fix This&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We check if includes() is available&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (!Array.prototype.includes) {  // ❌ If missing, define it
  Array.prototype.includes = function (searchElement) {
    return this.indexOf(searchElement) !== -1; // 🟢 Works everywhere
  };
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ Now, even older browsers can use includes()&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Common Polyfills in JavaScript&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here are some popular JavaScript features that often need polyfills:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;fetch() → Alternative: XMLHttpRequest&lt;/li&gt;
&lt;li&gt;Promise → Alternative: Callbacks&lt;/li&gt;
&lt;li&gt;Array.prototype.includes() → Alternative: indexOf()&lt;/li&gt;
&lt;li&gt;Object.assign() → Alternative: for...in loop&lt;/li&gt;
&lt;li&gt;String.prototype.startsWith() → Alternative: indexOf()&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;💡 These are just a few examples.There are many more polyfills available.&lt;/p&gt;

&lt;p&gt;👉 Need more? Check out core-js, a popular library for polyfills.&lt;/p&gt;

&lt;p&gt;🔗 core-js: &lt;a href="https://github.com/zloirock/core-js" rel="noopener noreferrer"&gt;https://github.com/zloirock/core-js&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Detecting Missing Features in Old Browsers&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before adding a polyfill, it's good to check if a browser supports a feature. Here's how:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Check "Can I Use" Data&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Use Can I Use to see browser compatibility for any feature&lt;br&gt;
Check browser compatibility on &lt;a href="https://caniuse.com" rel="noopener noreferrer"&gt;https://caniuse.com&lt;/a&gt;&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%2Fjpkg1nlu5vf00ux599f4.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%2Fjpkg1nlu5vf00ux599f4.png" alt="Image description" width="800" height="419"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Console Check in Old Browsers&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Open the Developer Console in an old browser (like IE11) and try running:&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(typeof Promise);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;If it logs "function" → ✅ Promise is supported.&lt;/li&gt;
&lt;li&gt;If it logs "undefined" → ❌ Promise is not supported, and you might need a polyfill.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If it logs &lt;code&gt;"undefined"&lt;/code&gt;, it means Promises are not supported.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. MDN Documentation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;MDN docs also show browser support details for different JavaScript features.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Final Thoughts&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Polyfills are lifesavers when working with older browsers. They make sure modern JavaScript works everywhere, keeping your website accessible to all users.&lt;/p&gt;

&lt;p&gt;However, be mindful of performance only use polyfills when necessary to avoid slowing down your site.&lt;/p&gt;

&lt;p&gt;So next time your code doesn’t work on an old browser, remember: a polyfill might be the fix.&lt;/p&gt;

&lt;p&gt;Stay curious, keep coding❤️&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Interview Questions &amp;amp; Answers on Polyfills&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. What is a polyfill in JavaScript?&lt;/strong&gt;&lt;br&gt;
A polyfill is a piece of code (usually JavaScript) that adds missing functionality to older browsers. It "fills in" features that a browser doesn’t support natively, allowing developers to use modern JavaScript features without worrying about compatibility issues.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. When should I use a polyfill?&lt;/strong&gt;&lt;br&gt;
You should use a polyfill when you're using modern JavaScript features (like Promise, Array.prototype.includes, fetch, etc.) that may not be supported in some browsers your users still use especially older versions of Internet Explorer or early versions of Safari.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. How does a polyfill work behind the scenes?&lt;/strong&gt;&lt;br&gt;
A polyfill checks if a feature exists in the browser, and if it doesn’t, it defines it using older JavaScript code. For example, before adding Array.prototype.includes, the polyfill will first check.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (!Array.prototype.includes) {
  Array.prototype.includes = function(searchElement, fromIndex) {
    // custom logic here
  };
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This way, it doesn’t overwrite the feature if the browser already supports it.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>JavaScript: Your First Baby Steps into Syntax &amp; Fundamentals</title>
      <dc:creator>Roja Gnanavel</dc:creator>
      <pubDate>Mon, 28 Apr 2025 14:21:28 +0000</pubDate>
      <link>https://forem.com/jslovers/javascript-your-first-baby-steps-into-syntax-fundamentals-3be8</link>
      <guid>https://forem.com/jslovers/javascript-your-first-baby-steps-into-syntax-fundamentals-3be8</guid>
      <description>&lt;p&gt;Ever opened a JavaScript file and wondered, "Why are there so many curly braces and semicolons?"🤯&lt;/p&gt;

&lt;p&gt;Welcome to JavaScript!🤓 Before diving into the fun stuff like functions, events, or cool tricks.You first need to understand its basic rules.&lt;/p&gt;

&lt;p&gt;Think of syntax as the grammar of JavaScript just like how we have grammar rules in English. If you follow the rules correctly, JavaScript understands what you're saying, and everything works fine.&lt;/p&gt;

&lt;p&gt;But if you make a mistake, like missing a bracket or writing something incorrectly, JavaScript won’t understand and will throw an error. Instead of saying "Oops, something’s wrong!", it will give you a real error message, like: &lt;/p&gt;

&lt;p&gt;🔴 &lt;strong&gt;SyntaxError: Unexpected token&lt;/strong&gt; (which means JavaScript found something it didn’t expect).&lt;/p&gt;

&lt;p&gt;It's JavaScript’s way of saying: "Hey, I don’t understand this 🤷‍♀️" &lt;/p&gt;

&lt;p&gt;Does that make sense now?😊&lt;/p&gt;

&lt;p&gt;Let’s break it down in a simple and fun way.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Statements &amp;amp; Expressions – The Building Blocks&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A statement is like a complete instruction in JavaScript&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let name = "Roja"; 
console.log(name);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each of these lines is a statement that tells JavaScript what to do.&lt;/p&gt;

&lt;p&gt;But what about expressions? 🤔&lt;/p&gt;

&lt;p&gt;An expression is a part of a statement that evaluates to a value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let sum = 5 + 3; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, 5 + 3 is an expression because it evaluates to 8.&lt;/p&gt;

&lt;p&gt;So, all expressions are part of a statement, but not all statements are expressions. Cool, right? 😎&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;2. Comments – Because Your Brain Won’t Remember Everything 🤯&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Comments are like notes in your code.They make your code easier to understand for you and anyone reading it later. Trust me, you’ll thank yourself for using them.&lt;/p&gt;

&lt;p&gt;🔹 &lt;strong&gt;Single line comments&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;// This is a single line comment
let age = 29;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔹 &lt;strong&gt;Multi line comments&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;/*
  This is a multi line comment.
  You can explain logic here.
*/
let isDeveloper = true;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use them.Future you will thank you.😎&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;3. JavaScript is Case Sensitive – Be Careful ⚠️&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;JavaScript treats uppercase and lowercase differently.So, "Name" and "name" are not the same.😱&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let Name = "Roja";  
let name = "Another Roja";  

console.log(Name); // Roja  
console.log(name); // Another Roja 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;strong&gt;4. Variables – The Right Way to Store Data&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;JavaScript gives us three ways to declare variables. Let’s break them down:&lt;/p&gt;

&lt;p&gt;🔹 &lt;strong&gt;var&lt;/strong&gt; - The old school one – Avoid It&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var city = "Chennai";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It works, but has weird scoping issues. Nobody uses var anymore.So, just skip it.&lt;/p&gt;

&lt;p&gt;🔹 &lt;strong&gt;let&lt;/strong&gt; - The go to choice&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let country = "India";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use let when the value might change later.&lt;/p&gt;

&lt;p&gt;🔹 &lt;strong&gt;const&lt;/strong&gt; - The unchangeable one&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const PI = 3.14159;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use const when the value should never change.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;5. Hoisting – JavaScript’s Magic Trick✨&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;JavaScript moves variable and function declarations to the top before running 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;console.log(name); // undefined
var name = "Roja";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With var, it’s hoisted but not initialized, so you get undefined.&lt;/p&gt;

&lt;p&gt;🚨 But let and const don’t work the same way!&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(age); 
let age = 29; 
// ❌ ReferenceError: Cannot access 'age' before initialization
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So always declare variables before using them!&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;6. Strict Mode – No More Silly Mistakes 🚫&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;"use strict" is a special directive in JavaScript that helps you write cleaner and more secure code. When you add it at the top of your script or function, it enables Strict Mode, which changes how JavaScript behaves in some important ways.&lt;/p&gt;

&lt;p&gt;Why use it?&lt;br&gt;
Strict mode helps you,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Catch common coding mistakes&lt;/li&gt;
&lt;li&gt;Prevent the use of undeclared variables&lt;/li&gt;
&lt;li&gt;Make your code more predictable and safer&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example: Without strict mode&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x = 10; // No error, but x is not declared properly
console.log(x);

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

&lt;/div&gt;



&lt;p&gt;Without "use strict", JavaScript would allow this mistake.&lt;/p&gt;

&lt;p&gt;Example: With strict mode&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"use strict";
x = 10; // Error! x is not declared
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Where to use it?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;At the top of a file
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"use strict";
// your code here
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Or inside a function
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function test() {
  "use strict";
  // strict mode only inside this function
}

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

&lt;/div&gt;



&lt;p&gt;That’s it. It’s just one line, but it helps avoid silly mistakes.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;7. Template Literals&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;you can join strings using either the + operator or template literals (also called template strings). However, template literals offer cleaner, more readable, and maintainable code.&lt;/p&gt;

&lt;p&gt;🔹 Using Template Literals:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Uses backticks (`) instead of regular quotes ("" or '')
// Variables and expressions are wrapped in ${}

let name = "Roja";
console.log(`Hello, ${name}!`); // Hello, Roja!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;strong&gt;8. Destructuring – Extracting Values Like a Pro🔥&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Instead of this old school way:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const user = { name: "Roja", age: 29 };
const userName = user.name;
const userAge = user.age;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use destructuring&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const { name, age } = user;
console.log(name, age); // Roja 29
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Works for arrays too:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const colors = ["red", "blue", "green"];
const [firstColor, secondColor] = colors;
console.log(firstColor, secondColor); // red blue
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Less code, more clarity.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;9. Spread &amp;amp; Rest Operators (...) – JavaScript’s Magic Trick ✨&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;🔹 &lt;strong&gt;Spread Operator&lt;/strong&gt; – Expanding Arrays&lt;br&gt;
Want to quickly copy or merge arrays? Use the spread operator.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const arr1 = [1, 2, 3];
const arr2 = [...arr1, 4, 5];
console.log(arr2); // [1, 2, 3, 4, 5]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔹 &lt;strong&gt;Rest Operator&lt;/strong&gt; – Collecting Multiple Values&lt;br&gt;
Need a function to accept multiple arguments? The rest operator has your back!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function sum(...numbers) {
  return numbers.reduce((total, num) =&amp;gt; total + num, 0);
}
console.log(sum(1, 2, 3, 4)); // 10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One spreads, the other gathers both make your code cleaner.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;10. Control Flow – Making JavaScript Decide for You 🤔&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;🔹 &lt;strong&gt;If-Else Statement&lt;/strong&gt; – Making simple decisions&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let temperature = 30;
if (temperature &amp;gt; 25) {
  console.log("It's hot outside.");
} else {
  console.log("It's cool today.");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔹 &lt;strong&gt;Switch Statement&lt;/strong&gt; – Handling multiple cases&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let day = "Monday";
switch (day) {
  case "Monday":
    console.log("Ugh, Monday blues.");
    break;
  case "Friday":
    console.log("Yay! Weekend is near.");
    break;
  default:
    console.log("Just another day.");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;strong&gt;11. Loops – Running Code Again &amp;amp; Again&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Loops help us execute the same block of code multiple times without repeating ourselves.&lt;/p&gt;

&lt;p&gt;🔹 &lt;strong&gt;For Loop&lt;/strong&gt; – Repeat something a fixed number of times&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (let i = 1; i &amp;lt;= 5; i++) {
  console.log("Number:", i);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Runs 5 times, increasing i each time.&lt;/p&gt;

&lt;p&gt;🔹 &lt;strong&gt;While Loop&lt;/strong&gt; – Repeat while a condition is true&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let count = 1;
while (count &amp;lt;= 3) {
  console.log("Counting:", count);
  count++;
}

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

&lt;/div&gt;



&lt;p&gt;Runs as long as count &amp;lt;= 3.&lt;/p&gt;

&lt;p&gt;🔹 &lt;strong&gt;Do-While Loop&lt;/strong&gt; – Always runs at least once&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let num = 5;
do {
  console.log("This runs at least once.");
  num++;
} while (num &amp;lt;= 3);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Runs once, even though the condition is false at the start.&lt;/p&gt;

&lt;p&gt;🔹 &lt;strong&gt;For-of Loop&lt;/strong&gt; – Loop through arrays&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fruits = ["Apple", "Banana", "Cherry"];
for (const fruit of fruits) {
  console.log(fruit);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Outputs each fruit one by one.&lt;/p&gt;

&lt;p&gt;🔹 &lt;strong&gt;For-in Loop&lt;/strong&gt; – Loop through object properties&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const user = { name: "Roja", age: 29 };
for (const key in user) {
  console.log(key, ":", user[key]);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Loops through keys in an object (name, age).&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;12. Functions – Write Once, Use Anytime&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;🔹 &lt;strong&gt;Function Declaration&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;function greet(name) {
  console.log("Hello, " + name + "!");
}
greet("Roja"); // Hello, Roja!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔹 &lt;strong&gt;Arrow Function&lt;/strong&gt; – The modern, shorter way&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const add = (a, b) =&amp;gt; a + b;
console.log(add(5, 3)); // 8
&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;Great job. You’ve taken your first baby steps into JavaScript by learning its basic rules and structure. Now you understand how statements, variables, loops, and functions work.&lt;/p&gt;

&lt;p&gt;But learning JavaScript takes time! The more you practice and explore, the better you’ll get.&lt;/p&gt;

&lt;p&gt;So, keep going, have fun, and enjoy your JavaScript journey.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Beyond JSON.stringify() + JSON.parse(): Deep Cloning Like a Pro with structuredClone()</title>
      <dc:creator>Roja Gnanavel</dc:creator>
      <pubDate>Mon, 21 Apr 2025 09:56:07 +0000</pubDate>
      <link>https://forem.com/roja_gnanavel/beyond-jsonstringify-jsonparse-deep-cloning-like-a-pro-with-structuredclone-56mp</link>
      <guid>https://forem.com/roja_gnanavel/beyond-jsonstringify-jsonparse-deep-cloning-like-a-pro-with-structuredclone-56mp</guid>
      <description>&lt;p&gt;As developers, we’ve all faced the challenge of trying to deeply clone objects in JavaScript. Whether it’s duplicating a complex object or ensuring we don’t unintentionally mutate data, cloning is a common task.&lt;/p&gt;

&lt;p&gt;For years, I stuck with the trusty JSON.stringify() + JSON.parse() combo. But as my projects grew, I realized that while this method worked most of the time, it wasn’t perfect. That’s when I discovered structuredClone(), a modern approach to deep cloning.&lt;/p&gt;

&lt;p&gt;Let’s dive into why you might want to switch to structuredClone() and how it solves the problems that JSON.stringify() + JSON.parse() just can’t handle.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Classic Approach: JSON.stringify() + JSON.parse()&lt;/strong&gt;&lt;br&gt;
For those who aren’t familiar with deep cloning, here’s the classic method&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const clone = JSON.parse(JSON.stringify(myObject));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It works like a charm in many cases, especially when dealing with simple objects. But here’s the catch, this method fails when you run into certain data structures, and that's when structuredClone() comes to the rescue.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When Does JSON.stringify() + JSON.parse() Fall Short?&lt;/strong&gt;&lt;br&gt;
JSON.stringify() + JSON.parse() can be used for deep cloning simple objects, but it has limitations and doesn't handle all data types correctly. Here are some common limitations&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Circular References&lt;/strong&gt;&lt;br&gt;
If your object has a circular reference (where an object refers to itself or another object that refers back to it), JSON.stringify() + JSON.parse() will throw an error.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const obj = { name: "Roja" };
obj.self = obj;  // Circular reference
const clone = JSON.parse(JSON.stringify(obj));  // Uncaught TypeError: Converting circular structure to JSON
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Functions &amp;amp; Methods&lt;/strong&gt;&lt;br&gt;
If your object contains functions, they will be lost during cloning because JSON.stringify() + JSON.parse() only serializes data, not methods.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const obj = { name: "Roja", greet: () =&amp;gt; "Hello!" };
const clone = JSON.parse(JSON.stringify(obj));
console.log(clone.greet);  // undefined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Dates&lt;/strong&gt;&lt;br&gt;
JSON.stringify() + JSON.parse() converts Date objects into strings, losing their functionality.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const obj = { date: new Date() };
const clone = JSON.parse(JSON.stringify(obj));
console.log(clone.date instanceof Date);  // false (it's now a string)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Complex Data Structures&lt;/strong&gt;&lt;br&gt;
If your object contains Map, Set, or Typed Arrays, they won’t be cloned properly.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const obj = { map: new Map([["key", "value"]]) };
const clone = JSON.parse(JSON.stringify(obj));
console.log(clone.map instanceof Map);  // false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Enter into structuredClone()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;structuredClone() addresses the limitations of JSON.stringify() + JSON.parse(). It's a native function that can deeply clone objects, including complex data types, such as circular references, Map, Set, Dates, and more.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const clone = structuredClone(myObject);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Unlike JSON.stringify() + JSON.parse(), structuredClone() can handle&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Circular references&lt;/li&gt;
&lt;li&gt;Maps and Sets&lt;/li&gt;
&lt;li&gt;Typed arrays and ArrayBuffers&lt;/li&gt;
&lt;li&gt;Date objects&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This method provides a much safer and more reliable way to clone complex objects.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When to Use structuredClone()?&lt;/strong&gt;&lt;br&gt;
If you're dealing with simple objects, JSON.stringify() + JSON.parse() might still be enough. But if your objects contain complex data structures, here’s when structuredClone() is the right choice:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Circular References&lt;/strong&gt;&lt;br&gt;
If you have an object with circular references, structuredClone() will clone it properly without throwing errors.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const obj = { name: "Roja" };
obj.self = obj;  // Circular reference
const clone = structuredClone(obj);
console.log(clone.self === clone);  // true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Maps and Sets&lt;/strong&gt;&lt;br&gt;
If your object includes Map or Set, structuredClone() will properly copy them, unlike JSON.stringify(), which can’t serialize them correctly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
const obj = { map: new Map([["key", "value"]]) };
const clone = structuredClone(obj);
console.log(clone.map instanceof Map);  // true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Typed Arrays &amp;amp; ArrayBuffers&lt;/strong&gt;&lt;br&gt;
structuredClone() can clone Typed Arrays and ArrayBuffers, which JSON.stringify() can’t handle.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const arr = new Uint8Array([1, 2, 3]);
const clone = structuredClone(arr);
console.log(clone instanceof Uint8Array);  // true

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Dates&lt;/strong&gt;&lt;br&gt;
If you have Date objects, structuredClone() will preserve their Date functionality, unlike JSON.stringify() + JSON.parse() which converts them to strings.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const original = { date: new Date() };
const clone = structuredClone(original);
console.log(clone.date instanceof Date);  // true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, When Should You Stick with JSON.stringify() + JSON.parse()?&lt;br&gt;
If your objects are simple, and you don’t have the complex structures mentioned above, JSON.stringify() + JSON.parse() might still work just fine. Here’s a quick checklist:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Dates as strings (No need to preserve functionality)&lt;/li&gt;
&lt;li&gt;Simple objects with no circular references&lt;/li&gt;
&lt;li&gt;No Maps, Sets, or Typed Arrays&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If this describes your use case, JSON.stringify() + JSON.parse() will likely suffice.&lt;/p&gt;

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

&lt;p&gt;structuredClone() is the go to method when you need to deeply clone complex objects like those with circular references, Maps, Sets, Typed Arrays, or Dates.&lt;/p&gt;

&lt;p&gt;If you're working with simple objects, JSON.stringify() + JSON.parse() is still a valid approach.&lt;/p&gt;

&lt;p&gt;structuredClone() helps you avoid errors and issues that arise with JSON.stringify() + JSON.parse() and makes deep cloning much simpler.&lt;/p&gt;

&lt;p&gt;Have You Used structuredClone() Yet?&lt;br&gt;
I’m really excited about this method and plan to start using it in my future projects. Have you had any experience with it? How has it worked for you? Drop your thoughts below.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>JavaScript Engines: The Core of Your Web Browser</title>
      <dc:creator>Roja Gnanavel</dc:creator>
      <pubDate>Mon, 17 Feb 2025 10:31:23 +0000</pubDate>
      <link>https://forem.com/jslovers/javascript-engines-the-core-of-your-web-browser-afn</link>
      <guid>https://forem.com/jslovers/javascript-engines-the-core-of-your-web-browser-afn</guid>
      <description>&lt;p&gt;&lt;strong&gt;What is JavaScript Engine&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Okay, you’ve probably come across the term "JavaScript engine," but what does it really mean? Well, a JavaScript engine is a program that reads and executes JavaScript code. It converts the code into machine language that the computer understands. JavaScript engines are used in browsers (like Chrome, Firefox) and environments like Node.js to run JavaScript code.&lt;/p&gt;

&lt;p&gt;Still confused? Let me make it easier for you: 😅&lt;/p&gt;

&lt;p&gt;Imagine the JavaScript engine is like Google Translate. JavaScript is like English, and the JavaScript engine is like Google Translate. You don’t understand English directly, so Google Translate changes it into Tamil (or whatever language works for you!). Similarly, the JavaScript engine turns JavaScript code into a language that the computer understands and follows without getting confused.&lt;/p&gt;

&lt;p&gt;Alright, now that we’ve got the basic idea of what a JavaScript engine is, you might wonder, why do we need it?&lt;/p&gt;

&lt;p&gt;We need a JavaScript engine because JavaScript makes websites interactive. Without the engine, the browser wouldn’t know how to read or run the code. Here’s why it’s important:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.Interactivity:&lt;/strong&gt; Websites need to respond to actions like clicking a button or filling out a form. The JavaScript engine makes sure this happens.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; When you click the "Submit" button, JavaScript makes sure the form data is sent to the server. Without the engine, the browser wouldn’t know what to do with your click!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.Performance:&lt;/strong&gt; The engine helps the code run faster and more smoothly, making websites quicker.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3.Cross-platform compatibility:&lt;/strong&gt; JavaScript works on different browsers and platforms (like Node.js), and the engine makes sure the code works well everywhere.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How JavaScript Engine Works&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s dive into how the engine actually works behind the scenes.&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%2Fhgqvzlb3u8kxsyhtlm6a.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%2Fhgqvzlb3u8kxsyhtlm6a.png" alt="Image description" width="800" height="215"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.Parsing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Parsing is the process of breaking down the code so the JavaScript engine can understand and run it. It happens in two steps&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lexical Analysis&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is where the engine scans the code from left to right, breaking it down into small chunks called tokens. Tokens are like words in a sentence. For Example, If code is&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let sum = 5 + 10;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The token would be:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;let -&amp;gt; keyword&lt;/li&gt;
&lt;li&gt;sum -&amp;gt; identifier&lt;/li&gt;
&lt;li&gt;= -&amp;gt; operator&lt;/li&gt;
&lt;li&gt;5 -&amp;gt; literal&lt;/li&gt;
&lt;li&gt;+ -&amp;gt; operator&lt;/li&gt;
&lt;li&gt;10 -&amp;gt; literal&lt;/li&gt;
&lt;li&gt;; -&amp;gt; punctuation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Syntax Analysis&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once Lexical Analysis is done, the tokens are arranged into something called an Abstract Syntax Tree (AST). Think of it as a tree like structure that shows how your code is organized.&lt;/p&gt;

&lt;p&gt;Here’s the cool part: this tree doesn’t just organize your code. It also checks if everything follows JavaScript’s rules.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let sum = 5+;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Oops! There’s a mistake here (you forgot something after the +).The parser will immediately catch this and throw a Syntax Error.&lt;/p&gt;

&lt;p&gt;In short, the AST makes sure your code is both structured and error-free.&lt;br&gt;
Here's a simple AST for the code above:&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%2Fb61ujhmf3vx3ui25bctc.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%2Fb61ujhmf3vx3ui25bctc.png" alt="Image description" width="524" height="431"&gt;&lt;/a&gt;&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%2Fmpcktlhvjoe1dr1oyzsw.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%2Fmpcktlhvjoe1dr1oyzsw.png" alt="Image description" width="762" height="740"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And if you're curious about the AST for your own code, it’s super easy to check! Just follow these steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go to &lt;a href="https://astexplorer.net/" rel="noopener noreferrer"&gt;https://astexplorer.net/&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Paste your code in the left panel.&lt;/li&gt;
&lt;li&gt;Pick Esprima or Babel as your parser.&lt;/li&gt;
&lt;li&gt;And there you have it! The AST tree will appear on the right side.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2.Interpretation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once parsing is done and we have our AST, the engine starts interpreting the code. This is when the engine reads through the code and makes things happen quickly. For example, when the code let sum = 5 + 10; runs, the engine calculates 5 + 10 to get 15 and assigns it to the variable sum.&lt;/p&gt;

&lt;p&gt;At this stage, the engine is prioritizing speed, getting the program up and running quickly, even if the code isn’t fully optimized yet.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3.JIT Compilation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now we get to the cool part: JIT (Just-In-Time) Compilation. This is where the engine really speeds things up.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It takes the code let sum = 5 + 10; and turns it into machine code that your computer can directly execute.&lt;/li&gt;
&lt;li&gt;It does this just before the code runs, making it fast and efficient.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example:&lt;br&gt;
The engine reserves memory for sum.&lt;br&gt;
It calculates 5 + 10, stores the result (15), and runs it smoothly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4.Optimization (Hot Path Detection)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now, the engine gets smarter. It monitors the code to identify "hot paths," which are frequently executed sections like loops or important functions.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If it notices that &lt;code&gt;5 + 10&lt;/code&gt; doesn’t involve any variable changes, it might precompute the result as &lt;code&gt;15&lt;/code&gt; and skip recalculating it repeatedly.&lt;/li&gt;
&lt;li&gt;The Optimizing JIT Compiler steps in here, fine-tuning the code to make these repetitive parts super fast.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;5.De-optimization (If Needed)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;But what happens if the code changes? For example, if you later change the value of sum to "hello":&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;The engine realizes &lt;code&gt;sum&lt;/code&gt; has changed from a number (&lt;code&gt;15&lt;/code&gt;) to a string (&lt;code&gt;"hello"&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;Now the engine knows that sum has changed from a number to a string. To ensure everything runs correctly, it de-optimizes the previously compiled machine code and makes sure the program works without any issues.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6.Execution Context and Scope&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once the code is parsed, the engine sets up the environment to run it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Global Execution Context:&lt;/strong&gt; This is the base environment created for the entire script. In browsers, the global object is window.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Function Execution Context:&lt;/strong&gt; Every time a function is called, a new execution context is created with its own scope (local variables, functions).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Execution Stack:&lt;/strong&gt; The engine uses a call stack to manage the execution contexts. When a function is invoked, its context is added to the stack. Once it completes, it is removed (popped off) from the stack.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, the engine is ready to manage memory and handle asynchronous tasks in the next steps.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7.Memory Management&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To store and retrieve data, JavaScript uses two main types of memory:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Heap Memory:&lt;/strong&gt; Used for objects, arrays, and functions (dynamic structures).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Stack Memory:&lt;/strong&gt; Used for primitive values (numbers, strings, booleans). The stack is faster but limited in size, while the heap handles more complex data.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;8.Event Loop&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;JavaScript’s single-threaded nature relies on the event loop to manage asynchronous tasks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Message Queue:&lt;/strong&gt; Tasks like setTimeout, API calls, and event handlers are queued up here after being initiated.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Event Loop:&lt;/strong&gt; Constantly checks if the call stack is empty. When it is, it moves tasks from the message queue to the stack for execution. This ensures asynchronous code doesn't block the main thread.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;9.Garbage Collection&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To avoid memory leaks, the JavaScript engine has a garbage collector. It uses an algorithm called Mark-and-Sweep to find and remove objects that are no longer in use, freeing up memory for other tasks.&lt;br&gt;
This is how JavaScript engine is working. 🎉&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Popular JavaScript Engines&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here are the most common JavaScript engines you’ll encounter:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;V8&lt;/strong&gt; (Chrome and Node.js) – Ignition (Interpreter) – TurboFan (Compiler)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SpiderMonkey&lt;/strong&gt; (Firefox) – jsinterp (Interpreter) – IonMonkey (Compiler)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;JavaScriptCore&lt;/strong&gt; (Safari) – JSC (Interpreter) – LLInt, FTLJIT (Compiler)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Chakra&lt;/strong&gt; (Internet Explorer) – Chakra Interpreter (Interpreter) – Chakra JIT (Compiler)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Each engine has its own strengths in how it interprets and compiles JavaScript, optimizing performance for their respective environments.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Comparison Of Engines&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;V8: Known for its efficient performance, used in both Chrome and Node.js.&lt;/li&gt;
&lt;li&gt;SpiderMonkey: Offers strong memory management and powers Firefox.&lt;/li&gt;
&lt;li&gt;JavaScriptCore: Optimized for Apple’s ecosystem, used in Safari.&lt;/li&gt;
&lt;li&gt;Chakra: Used in Internet Explorer, focusing on just-in-time compilation for speed.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;So, that’s how JavaScript engines work their magic! They handle everything like parsing, interpreting, optimizing, and managing memory. Whether you're working with Chrome, Firefox, Safari, or Node.js, each engine brings its own flavor to speed things up, making your experience faster and more efficient. So, next time you’re clicking around a website or running some code, remember there’s some cool engine magic happening in the background, making it all possible!! Hope this helps and you get a better idea of how things work under the hood! 😎&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
