<?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: Aiviraj Rajput</title>
    <description>The latest articles on DEV Community by Aiviraj Rajput (@abhiraj007).</description>
    <link>https://dev.to/abhiraj007</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%2F1276228%2F839d7170-c314-4911-b834-5c651a82e110.png</url>
      <title>DEV Community: Aiviraj Rajput</title>
      <link>https://dev.to/abhiraj007</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/abhiraj007"/>
    <language>en</language>
    <item>
      <title>Introduction to JavaScript Runtime Environments</title>
      <dc:creator>Aiviraj Rajput</dc:creator>
      <pubDate>Sun, 29 Jun 2025 20:26:08 +0000</pubDate>
      <link>https://dev.to/abhiraj007/introduction-to-javascript-runtime-environments-1a0m</link>
      <guid>https://dev.to/abhiraj007/introduction-to-javascript-runtime-environments-1a0m</guid>
      <description>&lt;h2&gt;
  
  
  What is a Runtime Environment
&lt;/h2&gt;

&lt;p&gt;A runtime environment is where your program will be executed. It determines what global objects your program can access and it can also impact how it runs. This article covers the two &lt;code&gt;JavaScript&lt;/code&gt;runtime environments:&lt;/p&gt;

&lt;p&gt;the runtime environment of a browser (like &lt;code&gt;Chrome&lt;/code&gt;, or &lt;code&gt;Firefox&lt;/code&gt;)&lt;br&gt;
the Node runtime environment&lt;/p&gt;
&lt;h2&gt;
  
  
  A Browser’s Runtime Environment
&lt;/h2&gt;

&lt;p&gt;The most common place where JavaScript code is executed is in a browser. For example, using any text editor, you could create a file on your own computer called &lt;code&gt;my_website.html&lt;/code&gt; and put the following HTML code inside:&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;!-- my_website.html --&amp;gt;
&amp;lt;html&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;h1&amp;gt; My Website &amp;lt;/h1&amp;gt;
    &amp;lt;script&amp;gt; window.alert('Hello World'); &amp;lt;/script&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save your file, then open your favorite browser. Most browsers will allow you to load websites that you have created locally by going to the menu File &amp;gt; Open File &amp;gt; &lt;code&gt;my_website.html.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Upon loading, the embedded  will execute and the &lt;code&gt;window.alert()&lt;/code&gt; method will create a pop-up box in your browser with the text &lt;code&gt;"Hello World".&lt;/code&gt; How is this possible? Where did the &lt;code&gt;window.alert()&lt;/code&gt; method come from and how can it control your browser?&lt;/p&gt;

&lt;p&gt;The answer is that you are executing this code in the browser’s runtime environment. The &lt;code&gt;window.alert()&lt;/code&gt; method is built into this environment and any program executed in a browser has access to this method. In fact, the window object provides access to a huge amount of data and functionality relating to the open browser window beyond just &lt;code&gt;.alert().&lt;/code&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Try replacing &lt;code&gt;window.alert()&lt;/code&gt; with &lt;code&gt;window.prompt()&lt;/code&gt; or &lt;code&gt;window.confirm()&lt;br&gt;
&lt;/code&gt;Applications created for and executed in the browser are known as front-end applications. For a long time, JavaScript code could only be executed in a browser and was used exclusively for creating front-end applications. In order to create back-end applications that could run on a computer WITHOUT a browser, you would need to use other &lt;code&gt;programming languages&lt;/code&gt; such as Java or PHP.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The Node Runtime Environment
&lt;/h2&gt;

&lt;p&gt;In 2009, the Node &lt;code&gt;runtime environment&lt;/code&gt; was created for the purpose of executing JavaScript code without a browser, thus enabling programmers to create full-stack (front-end and back-end) applications using only the JavaScript language.&lt;/p&gt;

&lt;p&gt;Node is an entirely different runtime environment, meaning that browser-environment data values and functions, &lt;code&gt;like window.alert(),&lt;/code&gt; can’t be used. Instead, the Node runtime environment gives back-end applications access to a variety of features unavailable in a browser, such as access to the server’s file system, database, and network.&lt;/p&gt;

&lt;p&gt;For example, suppose you created a file called &lt;code&gt;my-app.js.&lt;/code&gt; We can check to see the directory that this file is located in using the Node runtime environment variable process:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// my-app.js
console.log(process.env.PWD);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Notice that we are using console.log now instead of &lt;code&gt;window.alert()&lt;/code&gt; since the window object isn’t available&lt;br&gt;
process is an object containing data relating to the JavaScript file being executed. process.env is an object containing environment variables such as process.env.PWD which contains the current working directory &lt;code&gt;(and stands for “Print Working Directory”)&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To execute the JavaScript code in this file, first make sure that you have set up Node on your computer. Then, open up a terminal and run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ node my-app.js
/path/to/working/directory
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The node command tells your computer to execute the my-app.js file in the Node environment. You can also use the node command without a file argument to open up the &lt;code&gt;Node Read-Eval-Print-Loop (REPL)&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;$ node
&amp;gt; process.env.HOME
'/home/ccuser'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;A &lt;code&gt;runtime environment&lt;/code&gt; is where your program will be executed. JavaScript code may be executed in one of two runtime environments:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;a browser’s runtime environment&lt;/li&gt;
&lt;li&gt;the Node runtime environment&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In each of these environments, different data values and functions are available, and these differences help distinguish front-end applications from back-end applications.&lt;/p&gt;

&lt;p&gt;1.Front-end JavaScript applications are executed in a browser’s runtime environment and have access to the window object.&lt;br&gt;
2.Back-end JavaScript applications are executed in the Node runtime environment and have access to the file system, databases, and networks attached to the server.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Asynchronous Programming With Examples</title>
      <dc:creator>Aiviraj Rajput</dc:creator>
      <pubDate>Mon, 19 May 2025 18:26:51 +0000</pubDate>
      <link>https://dev.to/abhiraj007/asynchronous-programming-with-examples-96f</link>
      <guid>https://dev.to/abhiraj007/asynchronous-programming-with-examples-96f</guid>
      <description>&lt;p&gt;Asynchronous programming is a very important concept in JavaScript, through which tasks execute in a concurrent manner, making applications perform better and enhancing user experience. It does not work like synchronous programming, where tasks are executed one after the other. In order to run parallelly and perform better, &lt;code&gt;asynchronous programming&lt;/code&gt; does not allow the code execution to wait for any time-consuming operations, be it the fetching of data from a server or reading files.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Basics of Asynchronous programming Execution
&lt;/h2&gt;

&lt;p&gt;In this, functions are executed independently of the main program flow. It means, if one task is processing, the rest of the program can continue running and executing other tasks without waiting for &lt;code&gt;asynchronous operation&lt;/code&gt; to finish. There are several ways in &lt;code&gt;JavaScript&lt;/code&gt; to run program asynchronously:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Callbacks&lt;/li&gt;
&lt;li&gt;Promises&lt;/li&gt;
&lt;li&gt;Async/ Await&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Callback
&lt;/h2&gt;

&lt;p&gt;Callbacks are one of the essential concepts for the asynchronous programming of JavaScript. Basically, a callback is a function that is passed as an &lt;code&gt;argument&lt;/code&gt; to another function and is invoked or called later, after some operation has been completed. Callbacks find major use in cases where an operation will take some time to complete, for example, fetching data from a server or reading a file. Therefore , nesting of callback-based code to achieve control flow makes it hard to read and leads to phenomenon known as "callback hell".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function fetchData(callback) {
    setTimeout(() =&amp;gt; {
        callback("Data fetched successfully");
    }, 2000);
}

fetchData((data) =&amp;gt; {
    console.log(data);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Data fetched successfully
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;fetchData&lt;/code&gt; function simulates an asynchronous operation using setTimeout. When the operation completes, it invokes the callback function passed to it with the fetched data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Promises
&lt;/h2&gt;

&lt;p&gt;It was introduced in ES6 as a cleaner alternative to callbacks. A &lt;code&gt;promise&lt;/code&gt; represents the eventual completion or failure of an asynchronous operation and allows chaining of multiple asynchronous operations. This chaining really makes &lt;code&gt;promise-based&lt;/code&gt; code far more readable and manageable than &lt;code&gt;callback-based&lt;/code&gt; code. Therefore , promises can be in one of the three states : pending , resolved(fulfilled) and rejected.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function fetchData() {
    return new Promise((resolve, reject) =&amp;gt; {
        setTimeout(() =&amp;gt; {
            resolve("Data fetched successfully");
        }, 2000);
    });
}

fetchData().then((data) =&amp;gt; {
    console.log(data);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Data fetched successfully
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Async/Await
&lt;/h2&gt;

&lt;p&gt;Async/await is a feature in modern JavaScript, which makes the writing of asynchronous code easier for both reading and maintenance. It builds on top of the concept of promises and introduces a more natural and synchronous-like way of dealing with asynchronous operations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Basics of Async/Await
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Async Functions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;An async function is a special type of function that is capable of executing operations asynchronously within it. This is defined using the async keyword before a function declaration.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function fetchData() {
    // Asynchronous operations go here
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Await Functions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The await keyword is used inside async functions to pause the execution of the function until the Promise is resolved. It can only be used inside async functions, and it is followed by a promise. When await is used, the function execution is paused until the promise is resolved, returning its resolved value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function fetchData() {
    const data = await fetch('https://api.example.com/data');
    console.log(data);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, the async function &lt;code&gt;fetchData&lt;/code&gt; fetches data from an API using the fetch function. The await keyword pauses the function’s execution until it fetches the data from the API. Once fetched, it assigns the data to the data variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function fetchData() {
    return new Promise((resolve, reject) =&amp;gt; {
        setTimeout(() =&amp;gt; {
            resolve("Data fetched successfully");
        }, 2000);
    });
}

async function fetchDataAsync() {
    const data = await fetchData();
    console.log(data);
}

fetchDataAsync();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Data fetched successfully
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The function &lt;code&gt;fetchDataAsync&lt;/code&gt; is marked as async, so await can be used inside it. Inside fetchDataAsync, the await keyword causes the function to pause its execution until the &lt;code&gt;fetchData&lt;/code&gt; promise resolves, then assigns the resolved value to the data variable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Asynchronous programming lies at the heart of JavaScript development, allowing developers to create effective and responsive &lt;code&gt;web&lt;/code&gt; applications. Understand the fundamentals of asynchronous execution and how to master modern patterns in the asynchronous world, such as promises and async/await, to write clean, scalable, and maintainable code. Learn how to write high-quality and maintainable, &lt;code&gt;asynchronous programs&lt;/code&gt; with proper error handling and dependency management to achieve top-level performance in digital environments today.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>asychronousprogramming</category>
    </item>
    <item>
      <title>Scope in Javascript with example</title>
      <dc:creator>Aiviraj Rajput</dc:creator>
      <pubDate>Sat, 10 May 2025 19:42:59 +0000</pubDate>
      <link>https://dev.to/abhiraj007/scope-in-javascript-with-example-34d3</link>
      <guid>https://dev.to/abhiraj007/scope-in-javascript-with-example-34d3</guid>
      <description>&lt;p&gt;JavaScript is a powerful and versatile programming language that is widely used for web development. One of the key concepts in JavaScript is scope, which refers to the accessibility of variables, functions, and objects within a program. In this blog post, we will explain the different types of scope in JavaScript, including global scope, local scope, and function scope, and provide examples to help you understand how they work.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Global scope&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Global scope in JavaScript refers to variables, functions, and objects that can be accessed from anywhere within a program. These variables, functions, and objects are defined outside of any function or block of code.&lt;br&gt;
For example, consider the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let globalVariable = "Hello, World!";

function myFunction() {
  console.log(globalVariable); // prints "Hello, World!"
}

console.log(globalVariable); // prints "Hello, World!"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the variable &lt;code&gt;globalVariable&lt;/code&gt; is declared outside of any function or block of code, making it accessible from anywhere within the program. Both the &lt;code&gt;myFunction&lt;/code&gt; function and the &lt;code&gt;console.log&lt;/code&gt; statement outside of the function are able to access and print the value of &lt;code&gt;globalVariable&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Local scope&lt;/strong&gt;&lt;br&gt;
Local scope in JavaScript refers to variables, functions, and objects that can only be accessed within a specific block of code. These variables, functions, and objects are defined within a block of code, such as a &lt;code&gt;if&lt;/code&gt; statement or a &lt;code&gt;for&lt;/code&gt; loop.&lt;br&gt;
For example, consider the following code:&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) {
  let localVariable = "Hello, World!";
  console.log(localVariable); // prints "Hello, World!"
}

console.log(localVariable); // throws an error, localVariable is not defined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the variable &lt;code&gt;localVariable&lt;/code&gt; is defined within the &lt;code&gt;if&lt;/code&gt; statement, making it only accessible within that block of code. The &lt;code&gt;console.log&lt;/code&gt; statement within the if statement is able to access and print the value of &lt;code&gt;localVariable&lt;/code&gt;, but the &lt;code&gt;console.log&lt;/code&gt; statement outside of the &lt;code&gt;if&lt;/code&gt; statement throws an error because &lt;code&gt;localVariable&lt;/code&gt; is not defined in the global scope.&lt;/p&gt;

&lt;p&gt;In conclusion, understanding the concept of scope in JavaScript is essential for writing clean, efficient, and maintainable code. JavaScript has three main types of scope: global scope, function scope, and block scope (commonly referred to as local scope).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Global scope applies to variables and functions that are declared outside of any function or block, making them accessible throughout the entire program.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Function scope means variables declared within a function are only accessible inside that function.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Block scope, introduced with let and const in ES6, restricts variable access to the block (e.g., within {}) in which they are defined.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>javascriptscope</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
