<?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: Azhar Ahmed A</title>
    <description>The latest articles on Forem by Azhar Ahmed A (@azharahmed98).</description>
    <link>https://forem.com/azharahmed98</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%2F672317%2Fd3fd0f7c-ef36-40b6-80cc-a71e547553d6.jpeg</url>
      <title>Forem: Azhar Ahmed A</title>
      <link>https://forem.com/azharahmed98</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/azharahmed98"/>
    <language>en</language>
    <item>
      <title>Hi Everyone checkout my post on understanding variable in javascript</title>
      <dc:creator>Azhar Ahmed A</dc:creator>
      <pubDate>Wed, 19 Mar 2025 09:33:19 +0000</pubDate>
      <link>https://forem.com/azharahmed98/-pfe</link>
      <guid>https://forem.com/azharahmed98/-pfe</guid>
      <description>&lt;div class="ltag__link"&gt;
  &lt;a href="/azharahmed98" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&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%2Fuser%2Fprofile_image%2F672317%2Fd3fd0f7c-ef36-40b6-80cc-a71e547553d6.jpeg" alt="azharahmed98"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://dev.to/azharahmed98/understanding-var-let-and-const-in-javascript-3oo" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Understanding var, let and const in Javascript&lt;/h2&gt;
      &lt;h3&gt;Azhar Ahmed A ・ May 14 '22&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#javascriptbasics&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>javascriptbasics</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Understanding JavaScript Closures: A Hidden Gem</title>
      <dc:creator>Azhar Ahmed A</dc:creator>
      <pubDate>Wed, 19 Mar 2025 09:30:37 +0000</pubDate>
      <link>https://forem.com/azharahmed98/understanding-javascript-closures-a-hidden-gem-3p06</link>
      <guid>https://forem.com/azharahmed98/understanding-javascript-closures-a-hidden-gem-3p06</guid>
      <description>&lt;p&gt;JavaScript is a versatile language with many powerful features. One such feature, often overlooked by beginners, is &lt;strong&gt;closures&lt;/strong&gt;. Closures are a fundamental concept that can greatly enhance your coding skills and understanding of JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is a Closure?&lt;/strong&gt;&lt;br&gt;
A closure is a function that retains access to its lexical scope, even when the function is executed outside that scope. In simpler terms, a closure allows a function to access variables from its parent scope, even after the parent function has finished executing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why are Closures Important?&lt;/strong&gt;&lt;br&gt;
Closures are crucial for several reasons:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Data Privacy:&lt;/strong&gt; Closures enable the creation of private variables. This is useful for encapsulating data and preventing it from being accessed or modified directly.&lt;br&gt;
&lt;strong&gt;Function Factories:&lt;/strong&gt; They allow you to create functions dynamically, with each function having its own scope.&lt;br&gt;
&lt;strong&gt;Event Handlers:&lt;/strong&gt; Closures are often used in event handlers to maintain state.&lt;br&gt;
&lt;strong&gt;Example of a Closure&lt;/strong&gt;&lt;br&gt;
Let's look at a simple example to illustrate closures:&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;

  return function() {
    count++;
    console.log(count);
  };
}

const counter = createCounter();
counter(); // Output: 1
counter(); // Output: 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, createCounter returns a function that increments and logs the count variable. Even though createCounter has finished executing, the returned function still has access to count due to the closure.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Practical Use Cases&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Encapsulation&lt;/strong&gt;: Closures are perfect for encapsulating functionality and creating modules.&lt;br&gt;
&lt;strong&gt;Memoization&lt;/strong&gt;: They can be used to store results of expensive function calls and reuse them.&lt;br&gt;
&lt;strong&gt;Callbacks&lt;/strong&gt;: Closures are commonly used in asynchronous programming for callbacks.&lt;br&gt;
&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Closures are a powerful feature in JavaScript that can help you write more efficient and maintainable code. By understanding and utilizing closures, you can unlock new possibilities in your JavaScript programming journey.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Understanding var, let and const in Javascript</title>
      <dc:creator>Azhar Ahmed A</dc:creator>
      <pubDate>Sat, 14 May 2022 19:07:23 +0000</pubDate>
      <link>https://forem.com/azharahmed98/understanding-var-let-and-const-in-javascript-3oo</link>
      <guid>https://forem.com/azharahmed98/understanding-var-let-and-const-in-javascript-3oo</guid>
      <description>&lt;p&gt;Variables play an important part in any Programming Language as they act as the containers to store the Data &lt;br&gt;
Variables are pretty much required to perform any operation&lt;/p&gt;

&lt;p&gt;Javascript provides three ways of declaring the variables namely: &lt;br&gt;
1) var&lt;br&gt;
2) let &lt;br&gt;
3) const&lt;/p&gt;

&lt;p&gt;let's explore each variable type and its use cases.&lt;/p&gt;
&lt;h2&gt;
  
  
  Var:
&lt;/h2&gt;

&lt;p&gt;var declarations were predominant before the advent of ES6.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var greetings = 'Hello Javascript'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is one of the easiest ways to declare the variables.&lt;br&gt;
var variables can be re-declared and re-initialized.&lt;/p&gt;

&lt;p&gt;However, there are issues with the variables declared using var and which led to new ways of variable declarations&lt;/p&gt;
&lt;h2&gt;
  
  
  Scope of var:
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Scope&lt;/em&gt; essentially means where the variable is available to be accessed. Variables declared as var are global scoped or function/local scoped.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var globalVar = 'Welcome to my blog';

function readBlog() {
  var localVar = 'You are reading Crazy Js';
}

console.log(globalVar); // 'Welcome to my blog'
console.log(localVar); // Reference Error: localVar is not defined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the variable globalVar can be accessed anywhere across the program as it does not reside inside any function and is a globally scoped variable.&lt;/p&gt;

&lt;p&gt;whereas the localVar declared inside the function cannot be accessed outside. &lt;/p&gt;

&lt;h2&gt;
  
  
  Issues with var
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Variables can be re-declared and re-initialized with var:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When a variable is declared using var it can be re-declared and its value can be modified.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var greetings = 'Hello World!';
var greetings = 'Hello Javascript';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;as the variable with the same name is redeclared in the same scope it confuses.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Hoisting in var:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Variables declared as var can be accessed before they are declared this is possible because of a special feature called Hoisting.&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(greetings); // undefined
var greetings = 'Hello World!';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;var exists beyond the block in which it is declared:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Variables declared as var exist beyond the block in which they are defined if not defined inside a function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (true) {
var a = 'Hello'
}

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  let:
&lt;/h2&gt;

&lt;p&gt;let is now preferred variable declaration and comes as an improvement to var declarations.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let greetings = 'Hello Javascript'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Scope of let:
&lt;/h2&gt;

&lt;p&gt;Variable declared as let is block-scoped.&lt;/p&gt;

&lt;p&gt;A block is a chunk of code that resides in {}. &lt;br&gt;
let variables defined inside a block cannot be accessed outside it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function greetings() {
    let greetings = 'Hello Javascript'
}

console.log(greetings); // Reference error
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Improvements over var: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;let variables can be updated but not re-declared
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let greeting = 'hello'
greeting = 'Hi, Instead'

console.log(greeting); // 'Hi, Instead'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;this will result in an error&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let greeting = 'Hello';
let greeting = 'Hey'; // this will result in an error
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, if the same variable is defined in different scopes, there will be no error.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Hoisting of let
let variables are also hoisted but unlike var, let is not initialized as undefined and cannot be accessed until some value is assigned to let variables.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(greeting); // results in a reference error.
let greeting = 'Hello';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  const:
&lt;/h2&gt;

&lt;p&gt;const variables are used when we need to assign a constant value to a variable. const variables must be assigned with a value as soon as they are declared.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const greeting = 'Hello';
console.log(greeting); //Hello
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Scope of const:
&lt;/h2&gt;

&lt;p&gt;const variables are block-scoped similar to let.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function greetings() {
    const greetings = 'Hello Javascript'
}

console.log(greetings); // Reference error
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Improvements over var: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;const variables cannot be updated or re-declared
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const greeting = 'hello'
greeting = 'Hi, Instead' // syntax error
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Hoisting of const
const variables are also hoisted but unlike var, const is not initialized as undefined and cannot be accessed until some value is assigned to const variables.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(greeting); // results in a reference error.
const greeting = 'Hello';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Got any questions or suggestions? let me know&lt;br&gt;
Thanks for reading :)&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>javascriptbasics</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
