<?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: Imran Shaik</title>
    <description>The latest articles on DEV Community by Imran Shaik (@imranshaik012).</description>
    <link>https://dev.to/imranshaik012</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%2F851457%2Fa0a3ee12-eabc-4cc1-91bd-256e6dadcf73.png</url>
      <title>DEV Community: Imran Shaik</title>
      <link>https://dev.to/imranshaik012</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/imranshaik012"/>
    <language>en</language>
    <item>
      <title>Explain Closure in detail ?</title>
      <dc:creator>Imran Shaik</dc:creator>
      <pubDate>Mon, 23 Dec 2024 06:15:08 +0000</pubDate>
      <link>https://dev.to/imranshaik012/explain-closure-in-detail--3n3j</link>
      <guid>https://dev.to/imranshaik012/explain-closure-in-detail--3n3j</guid>
      <description>&lt;p&gt;A Closure is a feature in JavaScript where a function "remembers" the variable from its &lt;code&gt;lexical Scope&lt;/code&gt;(the scope in which it was created) even after the outer function has finished executing. This allows inner functions to access variables from their enclosing scope, even if the outer function is no longer active.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example of Closure
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function outerFunction(outerVariable){
  return function innerFunction(innerVariable){
     console.log(`outer variable : ${outerVariable}`);
     console.log(`inner variable : ${innerVariable}`);

};}

const closureFunction = outerFunction('outside');
closureFunction('inside');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>interview</category>
      <category>javascript</category>
      <category>react</category>
      <category>angular</category>
    </item>
    <item>
      <title>What is generator function in JavaScript? and How does it work?</title>
      <dc:creator>Imran Shaik</dc:creator>
      <pubDate>Sun, 22 Dec 2024 12:09:37 +0000</pubDate>
      <link>https://dev.to/imranshaik012/what-is-generator-function-in-javascript-and-how-does-it-work-5g8a</link>
      <guid>https://dev.to/imranshaik012/what-is-generator-function-in-javascript-and-how-does-it-work-5g8a</guid>
      <description>&lt;p&gt;A generator function in JavaScript is special type of function that can be paused and resumed during its execution. It is defined using &lt;code&gt;function*&lt;/code&gt; syntax  and uses the &lt;code&gt;yield&lt;/code&gt; keyword to produce values sequentially.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Characteristics of Generator function
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Define with &lt;strong&gt;function&lt;/strong&gt;* :
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function* generatorFunction(){
  yield 1;
  yield 2;
  yield 3;
  yield 4; 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2.Returns an Iterator&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;when a generator function is called, it doesn't execute immediately. 
Instead, it returns an iterator object.&lt;/li&gt;
&lt;li&gt;The iterator has a &lt;code&gt;next()&lt;/code&gt; method that is used to control the 
execution.

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;yield&lt;/code&gt;keyword: &lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;yield&lt;/code&gt;keyword is used to produce a value and pause the generator.&lt;/li&gt;
&lt;li&gt;when &lt;code&gt;next()&lt;/code&gt; is called again, the generator resumes execution from the
point where it was paused.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Example of Generator Function:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function* generatorFunction(){
   console.log("start");
   yield 1;
   console.log("Resume");
   yield 2; 
   console.log("End");

}
const gen = generatorFuntion();
console.log(gen.next());
console.log(gen.next());
console.log(gen.next());
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Output
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;start 
{value: 1, done: false}
Resume
{value: 2, done: false}
End
{Value: undefined, done: true}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How it Works
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Exectution on next():

&lt;ul&gt;
&lt;li&gt;when &lt;code&gt;next()&lt;/code&gt; is called for the first time, the generator starts 
execution and runs until the first &lt;code&gt;yield&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;it returns and object &lt;code&gt;{value, done}&lt;/code&gt;, where: 

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;value&lt;/code&gt;: The value produced by &lt;code&gt;yield&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;done&lt;/code&gt;: A boolean indicating  whether the generator has completed&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Pause and Resume.

&lt;ul&gt;
&lt;li&gt;The function pauses execution when it encounters &lt;code&gt;yield&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;It resumes from the paused when &lt;code&gt;next()&lt;/code&gt; is called again.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;completion: 

&lt;ul&gt;
&lt;li&gt;when the generator  function completes, the done property becomes 
&lt;code&gt;true&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>angule</category>
      <category>interview</category>
    </item>
    <item>
      <title>Reverse a string in JavaScript without using reverse()</title>
      <dc:creator>Imran Shaik</dc:creator>
      <pubDate>Sun, 22 Dec 2024 10:16:56 +0000</pubDate>
      <link>https://dev.to/imranshaik012/reverse-a-string-in-javascrip-without-using-reverse-method-5cgo</link>
      <guid>https://dev.to/imranshaik012/reverse-a-string-in-javascrip-without-using-reverse-method-5cgo</guid>
      <description>&lt;p&gt;Here is the JavaScript program to reverse a string without using the reverse() method&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function reverseString(str){
    let reversed= '';
    for(i=str.length-1; i&amp;gt;0; i--){
    reversed += str[i];

}
return reversed;
}
const originalString = "Hello world";
const reveresedString = reverseString(originalString);

console.log("original String", originalString);
console.log("reversed string", reveresedString );
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Explanation
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;The function &lt;strong&gt;reverseString&lt;/strong&gt; takes the input as string &lt;/li&gt;
&lt;li&gt;It iterates through the string from the last character to the first &lt;/li&gt;
&lt;li&gt;Each Character is appended to the &lt;strong&gt;reversed&lt;/strong&gt; string in reverse order&lt;/li&gt;
&lt;li&gt;Finally the reversed string is return.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This Program avoids the use of &lt;strong&gt;reverse()&lt;/strong&gt; and achieves the desired functionality.&lt;/p&gt;

&lt;p&gt;Detailed: How it works.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;str[i]:&lt;/strong&gt; Access the character at index &lt;strong&gt;i&lt;/strong&gt; in the string &lt;strong&gt;str&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;for Example, if str == "Hello ":
** str[4]** is &lt;strong&gt;'o'&lt;/strong&gt;
** str[3]** is &lt;strong&gt;'l'&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;reversed += str[i]:&lt;/strong&gt; this is shorthand for reversed = reversed + str[i]

&lt;ul&gt;
&lt;li&gt;it takes the current value or reversed, appends &lt;strong&gt;str[i]&lt;/strong&gt; to it, and then
updates reversed with this new value.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;*&lt;em&gt;Iterative Process: *&lt;/em&gt;&lt;br&gt;
Let's break it down for str = "abc"&lt;/p&gt;

&lt;h2&gt;
  
  
  Initial state:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;reversed=""(Empty string);&lt;/li&gt;
&lt;li&gt;Loop start at i=2(last character of the string)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Iteration 1 (i=2);&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;reversed +=str[2] -&amp;gt; reversed = "" + "c" -&amp;gt; reversed ="c"
Iteration 2 (i=1);&lt;/li&gt;
&lt;li&gt;reversed +=str[1] -&amp;gt; reversed = "c" + "b" -&amp;gt; reversed = "cb"
Iteration 3 (i=0);&lt;/li&gt;
&lt;li&gt;reversed +=str[0] -&amp;gt; reversed = "cb" + "a" -&amp;gt; reversed ="cba"&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;reversed = "cba"&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why use += ?
&lt;/h2&gt;

&lt;p&gt;The += operator simplifies the process of building the reversed string incrementally without needing an array or additional logic. It's efficient purpose in JavaScript&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>angular</category>
      <category>interview</category>
    </item>
    <item>
      <title>Different Ways to find maximum number in javascript</title>
      <dc:creator>Imran Shaik</dc:creator>
      <pubDate>Thu, 12 Dec 2024 09:39:22 +0000</pubDate>
      <link>https://dev.to/imranshaik012/different-ways-to-find-maximum-number-in-javascript-2amb</link>
      <guid>https://dev.to/imranshaik012/different-ways-to-find-maximum-number-in-javascript-2amb</guid>
      <description>&lt;p&gt;There are several ways to find the maximum number in javascript. they are as follows: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Using Max.math() with spread operator : &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;let arr = [89, 3, 2, 66, 3, 64, 100, 35]&lt;br&gt;
let max = Math.max(...arr)&lt;br&gt;
console.log(max);&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Using reduce() 
reduce method can be used to accumulate the max value by comparing each element.
&lt;code&gt;let arr = [89, 3, 2, 66, 3, 64, 100, 35]
let max = arr.reduce((acc, curr)=&amp;gt;(curr&amp;gt;acc?: curr: acc), -Infinity)
console.log(max)
&lt;/code&gt;
&lt;a class="mentioned-user" href="https://dev.to/here"&gt;@here&lt;/a&gt; - Infinity is used to ensure that the first comparision always return the first element&lt;/li&gt;
&lt;li&gt;using a For Loop: 
a 
``&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>javascript</category>
      <category>typescript</category>
      <category>react</category>
      <category>angular</category>
    </item>
    <item>
      <title>How do we sort an Array in Javascript without Sort function?</title>
      <dc:creator>Imran Shaik</dc:creator>
      <pubDate>Tue, 19 Nov 2024 14:42:11 +0000</pubDate>
      <link>https://dev.to/imranshaik012/how-do-we-sort-an-array-in-javascript-without-sort-function-31p8</link>
      <guid>https://dev.to/imranshaik012/how-do-we-sort-an-array-in-javascript-without-sort-function-31p8</guid>
      <description>&lt;p&gt;Sorting an array without using the default JavaScript sort function. &lt;br&gt;
There are multiple ways to sort an array in JavaScript. one of the most popular is Bubble Sort &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Problem&lt;/strong&gt; - you have an array of integers, sort the array &lt;br&gt;
Sorting can either be Ascending or descending.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const array = [5,3,8,6,2]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To sort an array Without using the JavaScript sort function is bubble sort. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bubble Sort&lt;/strong&gt;&lt;br&gt;
Bubble sort is one of the simplest sorting algorithm. It repeatedly step through  the list of array and compares the adjacent elements, and swap them if they are in the wrong order otherwise No swap. This process continues until the list is in sorted order.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function bubbleSort(arr){
  let n = arr.length;
  for (let i=0; i&amp;lt;n-1; i++){
    for (let j=0; j&amp;lt;n-i-1; j++){
      if(arr[j]&amp;gt;arr[j+1]){
        let temp = arr[j];
        arr[j] = arr[j+1];
        arr[j+1] = temp;
    }
}
  }
 return arr;
}

let array = [5,3,8,6,2]
console.log("sorted Array ", bubbleSort(array));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's how Bubble Sort works: An illustrated explanation is provided below.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pass 1:&lt;/strong&gt;&lt;br&gt;
Compare 5 and 3 → Swap → [3, 5, 8, 6, 2]&lt;br&gt;
Compare 5 and 8 → No swap → [3, 5, 8, 6, 2]&lt;br&gt;
Compare 8 and 6 → Swap → [3, 5, 6, 8, 2]&lt;br&gt;
Compare 8 and 2 → Swap → [3, 5, 6, 2, 8]&lt;br&gt;
Result after Pass 1: Largest element 8 is in its correct position.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pass 2:&lt;/strong&gt;&lt;br&gt;
Compare 5 and 3 → No Swap → [3, 5, 6, 2, 8]&lt;br&gt;
Compare 5 and 6 → No swap → [3, 5, 6, 2, 8]&lt;br&gt;
Compare 6 and 2 → Swap → [3, 5, 2, 6, 8]&lt;br&gt;
Compare 8 and 6 → No Swap → [3, 5, 2, 6, 8]&lt;br&gt;
Result after Pass 2: Largest element 6, 8 is in its correct position.&lt;/p&gt;

&lt;p&gt;In this way it will continue to swap the element until we get the sorted array i.e: [2, 3, 5, 6, 8]&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>arrays</category>
      <category>angular</category>
      <category>react</category>
    </item>
    <item>
      <title>Different ways to create Objects in Javascipt</title>
      <dc:creator>Imran Shaik</dc:creator>
      <pubDate>Tue, 19 Nov 2024 08:10:44 +0000</pubDate>
      <link>https://dev.to/imranshaik012/different-ways-to-create-objects-in-javascipt-20ce</link>
      <guid>https://dev.to/imranshaik012/different-ways-to-create-objects-in-javascipt-20ce</guid>
      <description>&lt;p&gt;There are multiple ways to create an objects in javascript.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Object Literals&lt;/strong&gt;: This is the simplest way to create an object 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;const obj = {
      name: "John", 
      age: 30,
      greet: function(){
      console.log("Object Literal Example")
}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Using Object Constructor:&lt;/strong&gt; Create an Object using the Object Constructor&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 = new object();
obj.name = "john";
obj.age = 30;
obj.greet = function(){
   console.log("Object Creation using Object Constructor");
}

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Using Constructor Function:&lt;/strong&gt;&lt;br&gt;
Define a custom constructor function and use it to create an objects&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function person(name, age){
  this.name= name;
  this.age = age;
  this.greet = function(){
  console.log(`Hello this object creation using constructor function ${this.name}`);
};
}
const john = new Person("John", 30)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascrip</category>
      <category>react</category>
      <category>angular</category>
      <category>node</category>
    </item>
  </channel>
</rss>
