<?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: Vidushi Agrawal</title>
    <description>The latest articles on DEV Community by Vidushi Agrawal (@vids18).</description>
    <link>https://dev.to/vids18</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%2F617274%2F7f1040cb-bf1a-4ece-b64d-5c57a93d27d1.png</url>
      <title>DEV Community: Vidushi Agrawal</title>
      <link>https://dev.to/vids18</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vids18"/>
    <language>en</language>
    <item>
      <title>Regular Expression</title>
      <dc:creator>Vidushi Agrawal</dc:creator>
      <pubDate>Wed, 07 May 2025 16:47:54 +0000</pubDate>
      <link>https://dev.to/vids18/regular-expression-597</link>
      <guid>https://dev.to/vids18/regular-expression-597</guid>
      <description>&lt;p&gt;I had read about regular expressions and thought of writing a blog on this. I will try to cover as much as possible. Let's start with the basic definition.&lt;/p&gt;

&lt;h2&gt;
  
  
  Regular Expression
&lt;/h2&gt;

&lt;p&gt;A regular expression (also “regexp”, or just “reg”) consists of a pattern and optional flags. In short, it is the method of matching strings to a pattern.&lt;/p&gt;

&lt;p&gt;Two syntaxes can be used to create a regular expression.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const regexp = new RegExp("pattern","flags");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OR&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const regexp = /pattern/; //without flags
const regexp = /pattern/flags; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Regex should be written within forward-slashes &lt;code&gt;/..../&lt;/code&gt;. These slashes play the same role as quotes in strings.&lt;/p&gt;

&lt;p&gt;The main difference between the syntaxes is that when the regular expression remains constant, use a pattern with a slash for better performance, but if the regular expression is changing, or you don't know the pattern, or getting it from another source like input fields, then a pattern with constructor should be used.&lt;br&gt;
&lt;em&gt;This is not a hard and fast rule, but an optimal way to do.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Let's see an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const regex = new RegExp("abc");
const regex = /abc/;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both of these regular expressions represent the same pattern, i.e &lt;em&gt;a&lt;/em&gt; is followed by &lt;em&gt;b&lt;/em&gt; followed by &lt;em&gt;c&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Flags
&lt;/h2&gt;

&lt;p&gt;Regular expressions may have flags that affect the search.&lt;br&gt;
There are only 6 of them in JavaScript: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;i&lt;/strong&gt;: With this flag, the search is case-insensitive&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;g&lt;/strong&gt;: With this flag, the search looks for a whole match. Without this flag, the search returns only the first match&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;m&lt;/strong&gt;: With this flag, the search matches not only at the beginning and the end of the string, but also at the start/end of the line.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;u&lt;/strong&gt;: Enables full Unicode support&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;s&lt;/strong&gt;: With this flag, the search allows a dot &lt;code&gt;.&lt;/code&gt; to match a newline character &lt;code&gt;\n&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;y&lt;/strong&gt;: With this flag, searching at the exact position in the text&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's understand it more with some examples.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let string = "You can and you will";
console.log(string.match(/You/gi));
  //(2) ["You", "you"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As we are using &lt;strong&gt;g&lt;/strong&gt; flag, it returns an array of all matches.&lt;br&gt;
Both &lt;em&gt;You&lt;/em&gt; and &lt;em&gt;you&lt;/em&gt; are found because &lt;strong&gt;i&lt;/strong&gt; flag makes the regex case-insensitive. Let's see what happens without the flag.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let string = "You can and you will";
console.log(string.match(/You/));
  //(1)["You"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before going through other flags, first understand &lt;strong&gt;&lt;em&gt;Character Classes&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Character Classes
&lt;/h2&gt;

&lt;p&gt;A character class is a special notation that matches any symbol from a certain set.&lt;br&gt;
The following character classes exist: &lt;br&gt;
&lt;code&gt;\d&lt;/code&gt; - digits&lt;br&gt;
&lt;code&gt;\s&lt;/code&gt; - space symbols, tabs, newlines&lt;br&gt;
&lt;code&gt;\w&lt;/code&gt; - Latin letters, digits, underscore '_'&lt;br&gt;
&lt;code&gt;.&lt;/code&gt; - any character if with the regexp 's' flag, otherwise any except a newline \n.&lt;/p&gt;
&lt;h3&gt;
  
  
  Inverse Classes
&lt;/h3&gt;

&lt;p&gt;Every character class has an inverse class; these are: &lt;br&gt;
&lt;code&gt;\D&lt;/code&gt; - non-digits&lt;br&gt;
&lt;code&gt;\S&lt;/code&gt; - all but \s&lt;br&gt;
&lt;code&gt;\W&lt;/code&gt; - all but \w&lt;/p&gt;
&lt;h2&gt;
  
  
  Dot Character Class
&lt;/h2&gt;

&lt;p&gt;A dot is a special character which matches "every character except new line".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;alert("ABC".match(/./)); 
      // A
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can even match it in the middle of a regex.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const regex = /Project.2/;
alert("Project-2".match(regex)); //Project-2
alert("Project 2".match(regex)); //null
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second example gives null. This is because a dot means "any character" but not "absence of character."&lt;br&gt;
Dot doesn't match character with new line without &lt;strong&gt;&lt;code&gt;s&lt;/code&gt;&lt;/strong&gt; flag.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let string = "A\nB"
alert(string.match(/A.B/)); //null
alert(string.match(/A.B/s)); //A  B
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above example is self-explanatory.&lt;/p&gt;

&lt;p&gt;Regular expressions are a powerful tool in JavaScript for pattern matching and text manipulation. While they may seem intimidating at first, understanding the basics, such as how to create regex using literals or constructors, the role of flags, and the meaning of character classes, can go a long way in making them approachable and useful. Whether you're validating input, searching within strings, or performing complex text transformations, regex can simplify your logic and make your code more efficient. As with any powerful tool, practice and experimentation are key to mastering regular expressions. Happy coding!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>regex</category>
    </item>
    <item>
      <title>Introduction to Next.js</title>
      <dc:creator>Vidushi Agrawal</dc:creator>
      <pubDate>Mon, 11 Mar 2024 10:28:44 +0000</pubDate>
      <link>https://dev.to/vids18/introduction-to-nextjs-2fj5</link>
      <guid>https://dev.to/vids18/introduction-to-nextjs-2fj5</guid>
      <description>&lt;p&gt;Delving into Next.js is essential for any seasoned developer. This robust React framework brings forth a myriad of benefits. Mastering Next.js equips you with the tools to craft web applications that are not just efficient and scalable but also embrace modern web development practices.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Next.js?
&lt;/h2&gt;

&lt;p&gt;Next.js is a React framework for building full-stack web applications. It offers an excellent developer experience and comes with many built-in features.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting started with Next.js
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Prerequisites:
&lt;/h3&gt;

&lt;p&gt;Before we begin, make sure you have a strong knowledge of HTML, CSS, JavaScript, and React JS.&lt;/p&gt;

&lt;h4&gt;
  
  
  Create your first Next.Js app:
&lt;/h4&gt;

&lt;p&gt;Open your terminal and use the following commands to create a new Next.js project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-next-app my-nextjs-app
cd my-nextjs-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;em&gt;my-nextjs-app&lt;/em&gt; with your preferred project name. This will set up a basic Next.js project structure for you.&lt;/p&gt;

&lt;h4&gt;
  
  
  Exploring the Project Structure:
&lt;/h4&gt;

&lt;p&gt;Only files &amp;amp; folders inside the &lt;strong&gt;&lt;em&gt;app&lt;/em&gt;&lt;/strong&gt; folder are considered for rendering.&lt;br&gt;
&lt;em&gt;&lt;strong&gt;page.js&lt;/strong&gt;&lt;/em&gt;: This file is used to render the pages. This file defines the content of the page. &lt;br&gt;
&lt;strong&gt;&lt;em&gt;layout.js&lt;/em&gt;&lt;/strong&gt;: This file defines the shell around one or more pages. It runs HTML and body tags. We don't have a head section in the layout.js's HTML tag as the title and description are defined in "metadata".&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjj3v2hntdnbku7drtplc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjj3v2hntdnbku7drtplc.png" alt="Metadata-Example" width="361" height="90"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;&lt;em&gt;icon.png&lt;/em&gt;&lt;/strong&gt;: When we will define this then this image will be considered a favicon.&lt;/p&gt;
&lt;h4&gt;
  
  
  Start the Development Server:
&lt;/h4&gt;

&lt;p&gt;To run the local server-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Create a new page:
&lt;/h4&gt;

&lt;p&gt;In the app, add a new directory &lt;strong&gt;&lt;em&gt;about&lt;/em&gt;&lt;/strong&gt; and add a new &lt;em&gt;page.js&lt;/em&gt; file. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frn67dl90fknyu8z6zc4q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frn67dl90fknyu8z6zc4q.png" alt="About Page folder" width="284" height="166"&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;/about/page.js

export default function AboutPage() {
  return (
    &amp;lt;main&amp;gt;
      &amp;lt;h1&amp;gt;About Us&amp;lt;/h1&amp;gt;
    &amp;lt;/main&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create a &lt;em&gt;&lt;a href="http://localhost:3000/about"&gt;http://localhost:3000/about&lt;/a&gt;&lt;/em&gt; page. The content should be written on the page.js file.&lt;/p&gt;

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

&lt;p&gt;Bravo! You started learning the next.js and created a new page. Feel free to create more pages and explore. Keep learning and experimenting!&lt;/p&gt;

</description>
      <category>learning</category>
      <category>nextjs</category>
      <category>react</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Microtasks</title>
      <dc:creator>Vidushi Agrawal</dc:creator>
      <pubDate>Sat, 15 May 2021 16:52:05 +0000</pubDate>
      <link>https://dev.to/vids18/microtasks-2jko</link>
      <guid>https://dev.to/vids18/microtasks-2jko</guid>
      <description>&lt;p&gt;Event Loop is used to perform asynchronous function in JavaScript. Event Loop monitors message queue and the execution stack to make sure that the callback functions are executed just after the execution stack gets empty. The callback functions are divided into macro-tasks and micro-tasks.&lt;br&gt;
We will see the execution of microtask in the blog.&lt;/p&gt;

&lt;h3&gt;
  
  
  How is microtask executed?
&lt;/h3&gt;

&lt;p&gt;Event Loop has a task queue also called macro-task. Once the callback in the message queue starts executing, it executes one macro-task first. When the macro-task gets executed then it goes to execute the micro-task queue. During the execution of the micro-task queue, if any additional microtasks gets added to the end of the queue then it is also executed at that same execution. Once the micro-task gets empty, it starts executing the macro-task queue.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lVICej0b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/2aefeebf5fe641258f65ce5fb02f0d8d%7Etplv-k3u1fbpfcp-zoom-1.image" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lVICej0b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/2aefeebf5fe641258f65ce5fb02f0d8d%7Etplv-k3u1fbpfcp-zoom-1.image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  Problems with Micro-task
&lt;/h5&gt;

&lt;p&gt;It might happen that the micro-task keep queuing more micro-tasks and get stuck in an infinite loop. Render is also blocked during the execution of the micro-task queue. So if infinite loop is created or execution of microtask is taking too long, then the page will become unresponsive.  &lt;/p&gt;

&lt;p&gt;To avoid this, JS limits the  simultaneous number of micro-tasks execution to 1000. This means that after 1000 micro-tasks, it has to pick up a macro-task and after the execution get back to the micro-task queue.&lt;/p&gt;

&lt;h3&gt;
  
  
  Promise callbacks as Micro-task
&lt;/h3&gt;

&lt;p&gt;Promise callbacks should be queued as micro-task. This is because if we queue promise callbacks as macro-tasks then it may lead to performance problems, as callback may be unnecessarily be delayed by task-related thing such as rendering. It also causes &lt;em&gt;non-determinism&lt;/em&gt; due to interaction with other task sources, and can break interactions with APIs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;We discussed about the execution of micro-task and the merits and demerits related to it. &lt;/p&gt;

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