<?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: sagar</title>
    <description>The latest articles on DEV Community by sagar (@sagar7170).</description>
    <link>https://dev.to/sagar7170</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%2F1129065%2F7c97e53a-cf84-4def-b4e5-429e186391b6.jpeg</url>
      <title>DEV Community: sagar</title>
      <link>https://dev.to/sagar7170</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sagar7170"/>
    <language>en</language>
    <item>
      <title>querySelector vs querySelectorAll in javascript</title>
      <dc:creator>sagar</dc:creator>
      <pubDate>Wed, 16 Oct 2024 18:17:31 +0000</pubDate>
      <link>https://dev.to/sagar7170/queryselector-vs-queryselectorall-in-javascript-53kd</link>
      <guid>https://dev.to/sagar7170/queryselector-vs-queryselectorall-in-javascript-53kd</guid>
      <description>&lt;p&gt;&lt;em&gt;querySelector vs querySelectorAll both are used select and manupulate DOM elements but they have some different behavior&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.querySelector&lt;/strong&gt;&lt;br&gt;
Returns the first matching element in the DOM that satisfies the CSS selector. If no match is found, it returns null.&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;nav&amp;gt;
&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;body&amp;gt;
&amp;lt;nav class='nav'&amp;gt;
&amp;lt;a href="/html/"&amp;gt;HTML&amp;lt;/a&amp;gt; |
&amp;lt;a href="/css/"&amp;gt;CSS&amp;lt;/a&amp;gt; |
&amp;lt;a href="/js/"&amp;gt;JavaScript&amp;lt;/a&amp;gt; |
&amp;lt;a href="/python/"&amp;gt;Python&amp;lt;/a&amp;gt;
&amp;lt;/nav&amp;gt;

&amp;lt;script&amp;gt;

const link  = document.querySelector("a")
console.log(link); // &amp;lt;a href="/html/"&amp;gt;HTML&amp;lt;/a&amp;gt;

&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;in the above code example we can see inside script tag i have selected a tag and we are getting only first one matching element not all.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.querySelectorAll&lt;/strong&gt;&lt;br&gt;
Returns all matching elements as a NodeList, which is a collection of elements. If no match is found, it returns an empty NodeList.&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;nav&amp;gt;
&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;body&amp;gt;
&amp;lt;nav class='nav'&amp;gt;
&amp;lt;a href="/html/"&amp;gt;HTML&amp;lt;/a&amp;gt; |
&amp;lt;a href="/css/"&amp;gt;CSS&amp;lt;/a&amp;gt; |
&amp;lt;a href="/js/"&amp;gt;JavaScript&amp;lt;/a&amp;gt; |
&amp;lt;a href="/python/"&amp;gt;Python&amp;lt;/a&amp;gt;
&amp;lt;/nav&amp;gt;

&amp;lt;script&amp;gt;

const link  = document.querySelectorAll("a")
console.log(link); // // [object NodeList] (4) [&amp;lt;a/&amp;gt;,&amp;lt;a/&amp;gt;,&amp;lt;a/&amp;gt;,&amp;lt;a/&amp;gt;]

&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;in the above code example we can see inside script tag i have selected a tag and we are getting all matching elements as a NodeList.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Best Way to add Javascript file in HTML</title>
      <dc:creator>sagar</dc:creator>
      <pubDate>Wed, 09 Oct 2024 10:49:51 +0000</pubDate>
      <link>https://dev.to/sagar7170/best-way-to-add-javascript-file-in-html-328</link>
      <guid>https://dev.to/sagar7170/best-way-to-add-javascript-file-in-html-328</guid>
      <description>&lt;p&gt;In HTML, there are several ways to include a JavaScript file. I'll explain four different methods, their drawbacks, and finally, highlight the best approach.&lt;/p&gt;

&lt;p&gt;1.&lt;code&gt;&amp;lt;script src="custom.js"&amp;gt;&amp;lt;/script&amp;gt; in &amp;lt;head&amp;gt;&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;&amp;lt;!DOCTYPE html&amp;gt; 
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
    &amp;lt;title&amp;gt;Document&amp;lt;/title&amp;gt;
    &amp;lt;script src="custom.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;

&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this approach while parsing code, javascript file loaded first before html inside body and If the JavaScript tries to manipulate elements in the body that haven’t been parsed yet, it can lead to errors, as the HTML content hasn’t fully loaded.&lt;/p&gt;

&lt;p&gt;This blocking behavior delays the parsing and rendering of the rest of the page, affecting performance and user experience.&lt;/p&gt;

&lt;p&gt;2.&lt;code&gt;&amp;lt;script src="custom.js"&amp;gt;&amp;lt;/script&amp;gt; in &amp;lt;body&amp;gt; (at the end)&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;&amp;lt;!DOCTYPE html&amp;gt; 
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
    &amp;lt;title&amp;gt;Document&amp;lt;/title&amp;gt; 
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;script src="custom.js"&amp;gt;&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;In this approach, the HTML is fully parsed before the JavaScript is loaded and executed, preventing errors related to missing DOM elements. This approach is all good but since HTML parsing and JavaScript loading happen sequentially, it can take longer duration overall, as the two processes occur at different times&lt;/p&gt;

&lt;p&gt;3.&lt;code&gt;&amp;lt;script src="custom.js" async&amp;gt;&amp;lt;/script&amp;gt; in &amp;lt;head&amp;gt;&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;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
    &amp;lt;title&amp;gt;Document&amp;lt;/title&amp;gt;
    &amp;lt;script src="custom.js" async&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this approach, we make the JavaScript asynchronous, so it doesn’t block the HTML from loading. Both HTML parsing and JavaScript loading happen in parallel. However, if the JavaScript executes before the HTML is fully parsed and js tries to manipulate html elements that haven’t loaded yet, it can cause errors.&lt;br&gt;
Note: — this approach can save the time but by loading html ,js simultaneously but more vulnerable to error&lt;/p&gt;

&lt;p&gt;4.&lt;code&gt;&amp;lt;script src="custom.js" defer&amp;gt;&amp;lt;/script&amp;gt; in &amp;lt;head&amp;gt;&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;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
    &amp;lt;title&amp;gt;Document&amp;lt;/title&amp;gt;
    &amp;lt;script src="custom.js" defer&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;

&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This approach is similar to the third one, where both HTML parsing and JavaScript loading happen in parallel. However, even if the JavaScript loads first, the browser waits until the HTML is fully parsed before executing the script&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary: Best Approach
&lt;/h2&gt;

&lt;p&gt;The best way is usually to use:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;script src="custom.js" defer&amp;gt;&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;br&gt;
Why:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It doesn’t block the HTML parsing (non-blocking download).&lt;/li&gt;
&lt;li&gt;It ensures the script runs after the DOM is fully parsed, making it safer for manipulating DOM elements.&lt;/li&gt;
&lt;li&gt;It preserves script execution order if you have multiple deferred scripts.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In cases where the script is independent of DOM content (like tracking scripts or ads), you can use async for better performance.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>let, const , var difference in Javascript?</title>
      <dc:creator>sagar</dc:creator>
      <pubDate>Tue, 13 Aug 2024 09:13:14 +0000</pubDate>
      <link>https://dev.to/sagar7170/let-const-var-difference-in-javascript-2d82</link>
      <guid>https://dev.to/sagar7170/let-const-var-difference-in-javascript-2d82</guid>
      <description>&lt;p&gt;In JavaScript, let, const, and var are used to declare variables, but they are different in three ways:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Scope&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;2. Reassignment&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;3. Hoisting&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  1.Scope:
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;var&lt;/strong&gt; is a functional scope means we access var variable anywhere within the function if we try access it outside function it will show error undefined&lt;br&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;
function demo(){
  if(true){
    var n = 3;
  }
  console.log(n)
}
console.log(n) //ReferenceError: n is not defined
demo();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;let&lt;/strong&gt; &amp;amp; &lt;strong&gt;const&lt;/strong&gt; are block means we can access them within the scope only otherwise it will show undefined error&lt;br&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;function demo(){
  if(true){
    let n = 3;
    const m = 5;
     console.log(n) // 3
     console.log(m) // 5
  }
  console.log(n) //ReferenceError: n is not defined
  console.log(m) //ReferenceError: n is not defined
}
console.log(n) //ReferenceError: n is not defined
console.log(m) //ReferenceError: n is not defined
demo();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2.Reassignment
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;var&lt;/strong&gt;: Can be reassigned and redeclared within its scope.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;let&lt;/strong&gt;: Can be reassigned but not redeclared within its scope.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;const&lt;/strong&gt;: Cannot be reassigned or redeclared. The variable itself is immutable, though objects and arrays assigned to const can still be modified
.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  3.Hoisting
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;var&lt;/strong&gt; is hoisted, meaning it's accessible before its declaration, but its value will be undefined until the code reaches the line where the variable is initialized.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;let&lt;/strong&gt; is also hoisted, but unlike var, it cannot be accessed before its declaration due to the "temporal dead zone."&lt;/li&gt;
&lt;li&gt;Variables declared with &lt;strong&gt;const&lt;/strong&gt; are also hoisted but must be initialized at the time of declaration and cannot be reassigned. However, if the variable is an object or array, its contents can be modified (e.g., adding or removing items from an array).
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// var example
console.log(a); // undefined (due to hoisting)
var a = 10;
console.log(a); // 10

// let example
console.log(b); // ReferenceError: Cannot access 'b' before initialization
let b = 20;
console.log(b); // 20

// const example
const c = 30;
c = 40; // TypeError: Assignment to constant variable
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>forEach vs map method javascript</title>
      <dc:creator>sagar</dc:creator>
      <pubDate>Mon, 12 Aug 2024 08:55:58 +0000</pubDate>
      <link>https://dev.to/sagar7170/foreach-vs-map-method-javascript-2351</link>
      <guid>https://dev.to/sagar7170/foreach-vs-map-method-javascript-2351</guid>
      <description>&lt;p&gt;forEach and map method both use to iterate over arrays , but they serve different purposes and have distinct behaviors.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.forEach method&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The forEach method is used for iterating through each element of an array. It doesn’t create a new array; instead, it directly modifies the elements of the existing array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const numbers = [1, 2, 3, 4, 5];

numbers.forEach(function(number) {
  console.log(number * 2);
});

// Output:
// 2
// 4
// 6
// 8
// 10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;forEach used when your purpose is to iterate over each element of array without needing to create new array.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. map method&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;map method on other hand also used for iterating through each element of an array but it can return new modified array without changing the original array&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const numbers = [1, 2, 3, 4, 5];

const doubledNumbers = numbers.map(function(number) {
  return number * 2;
});

console.log(doubledNumbers); // Output: [2, 4, 6, 8, 10]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;map method used when your purpose is to return new modified array&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In summary:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Use forEach when you want to iterate through an array and perform side effects or actions on each element without creating a new array.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use map when you want to iterate through an array, transform its elements using a function, and create a new array with the transformed values.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Note:-&lt;/strong&gt; Remember that both methods iterate over each element in the array, so the provided function will be executed for each element. The main difference lies in the purpose and outcome of using each method.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>What are AEM Components?</title>
      <dc:creator>sagar</dc:creator>
      <pubDate>Mon, 12 Aug 2024 06:26:04 +0000</pubDate>
      <link>https://dev.to/sagar7170/what-are-aem-components-5d9j</link>
      <guid>https://dev.to/sagar7170/what-are-aem-components-5d9j</guid>
      <description>&lt;p&gt;&lt;strong&gt;AEM&lt;/strong&gt; components are the modular units which realize specific functionality to present your content on your website.&lt;/p&gt;

&lt;p&gt;Think of &lt;strong&gt;AEM components&lt;/strong&gt; like building blocks for a website. Each component is a little piece of the website that does something specific, like showing text, an image, a button, or even more complex things like a slideshow or a contact form.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Components are the Basic building blocks of the AEM website. They can be easily dragged and dropped to the pages&lt;/li&gt;
&lt;li&gt;Components are the reusable modules that implements specific application logic to render the content of our website&lt;/li&gt;
&lt;li&gt;Collection of scripts&lt;/li&gt;
&lt;li&gt;Modular and Re-usable unit&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Web content management(WCM) have two components:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Core Components&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Foundation Components&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Core Components&lt;/strong&gt;: Modern, flexible, and customizable components provided by Adobe for creating rich web content in AEM. Recommended for new projects.&lt;br&gt;
&lt;strong&gt;Foundation Components&lt;/strong&gt;: Older, less flexible components that are still available for legacy support. Less recommended for new projects but useful for maintaining older sites.&lt;/p&gt;

</description>
      <category>aem</category>
      <category>webdev</category>
    </item>
    <item>
      <title>4 ways to iterate over “objects” in javascript</title>
      <dc:creator>sagar</dc:creator>
      <pubDate>Sun, 14 Jul 2024 07:35:16 +0000</pubDate>
      <link>https://dev.to/sagar7170/4-ways-to-iterate-over-objects-in-javascript-1e8p</link>
      <guid>https://dev.to/sagar7170/4-ways-to-iterate-over-objects-in-javascript-1e8p</guid>
      <description>&lt;p&gt;In javascript object contain the key value pair properties and iterating over object is different from arrays . Objects can be iterated using for...in loops and Object.keys(), Object.values(), and Object.entries(). Let’s see how you can use each method:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. using &lt;code&gt;for...in&lt;/code&gt; method&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;const person = {
    name: 'John',
    age: 30,
    occupation: 'Engineer'
  };
 for(let key in persons){
     console.log(`${person[key]} : ${key}`)
}
   //output
   // name: 'John',
   // age: 30,
   // occupation: 'Engineer'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2.Using Object.keys(): method&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;object.keys()&lt;/strong&gt; is a javascript method which take object as argument and return array of keys&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const person = {
    name: 'John',
    age: 30,
    occupation: 'Engineer'
  };
const Object_keys = Object.keys(person);
console.log(Object_keys)// [ 'name', 'age', 'occupation']```




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

&lt;/div&gt;

&lt;p&gt;we can use object.keys() to iterate over object&lt;/p&gt;

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

const person = {
    name: 'John',
    age: 30,
    occupation: 'Engineer'
  };
const Object_keys = Object.keys(person);

//here first i have used Object_keys array which i got from Object.keys(person);
for(let i = 0 ; i&amp;lt;Object_keys.length;i++){
  console.log(`${Object_keys[i]} : ${person[Object_keys[i]]}`);
}

//here i have used Object_keys array which i got from Object.keys(person);
for(let keys of Object_keys){
  console.log(`${keys} : ${person[keys]}`);
}

// here i have just directly use object.key() method
for(let keys of Object.keys(person)){
  console.log(`${keys}: ${person[keys]}`);
}

// all three ways will give same output
name : John
age : 30
occupation : Engineer


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

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;3.Using Object.entries():&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Object.entries()&lt;/strong&gt; is a javascript method which take object as argument and return 2d array of key value pair&lt;/p&gt;

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

const person = {
    name: 'John',
    age: 30,
    occupation: 'Engineer'
  };

const Object_keyValue = Object.entries(person);

//output
// [ [ 'name', 'John' ], [ 'age', 30 ], [ 'occupation', 'Engineer' ] ]


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

&lt;/div&gt;

&lt;p&gt;we can use &lt;strong&gt;Object.entries()&lt;/strong&gt; to iterate over object&lt;/p&gt;

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

const person = {
    name: 'John',
    age: 30,
    occupation: 'Engineer'
  };

for (const [key, value] of Object.entries(person)) {
  console.log(`${key} : ${value}`);
}

//output
   // name: 'John',
   // age: 30,
   // occupation: 'Engineer'


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

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;4. Using Object.values():&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Object.values()&lt;/strong&gt; returns an array of an object's own enumerable property values. This can be useful if you're only interested in the values and not the keys.&lt;/p&gt;

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

const myObject = {
  prop1: 'value1',
  prop2: 'value2',
  prop3: 'value3'
};

const values = Object.values(myObject);

for (const value of values) {
  console.log(value);
}



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

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>web</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Hoisting in javascript ?</title>
      <dc:creator>sagar</dc:creator>
      <pubDate>Sat, 13 Jul 2024 06:45:46 +0000</pubDate>
      <link>https://dev.to/sagar7170/hoisting-in-javascript--46md</link>
      <guid>https://dev.to/sagar7170/hoisting-in-javascript--46md</guid>
      <description>&lt;p&gt;“Hoisting is behavior in javascript where all the variable and function declaration moved to the top of the containing scope during compilation phase before code execution”&lt;/p&gt;

&lt;p&gt;You may came across this definition everywhere but “it is a myth that all the variable and function declaration physically top of the code ” This is not true!&lt;/p&gt;

&lt;p&gt;But instead , In hoisting all the variable and function declaration already get assigned memory before code execution in the compilation and stay exactly where we typed them.&lt;/p&gt;

&lt;p&gt;So exactly how var/let/const and functions are hoisted.&lt;/p&gt;

&lt;p&gt;Here are 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;console.log(a) // undefined
console.log(b) // ReferenceError
console.log(c) // ReferenceError

var a = 10;
let b = 20;
const c = 30;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Variable declared with var will be hoisted and during compilation time var variable assigned in memory with value undefined that why when we console var before declaration we get undefined&lt;/p&gt;

&lt;p&gt;Variable declared with const/let will also hoisted but not initialized with undefined . we can not access them before declaration , otherwise we receive a ReferenceError. This is because of Temporal Dead Zone, a time where variable exist but not initialized .&lt;/p&gt;

&lt;p&gt;But what about function&lt;/p&gt;

&lt;p&gt;Well it depends how we declare our functions. See below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;greet1();
greet2();
greet3();
greet4();

//function declaration is full hoisted
function greet1(){
    console.log("greet1");
}

// TypeError: greet2 is not a function
var greet2 = function(){
    console.log("greet2");
}

 // ReferenceError: Cannot access 'greet3' before initialization
let greet3 = function(){
    console.log("greet2");
}

// ReferenceError: Cannot access 'greet4' before initialization
const greet4 = function(){
    console.log("greet2");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Traditional function declaration is fully hoisted means we can call it throughout the code.&lt;/p&gt;

&lt;p&gt;but with function expression , we are unable to it before it has been declared . This is why three function declared with variables gives us an error. So we have two option either we change the function expression to function declaration or call the function after declarations.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>“==” and “===” difference in javascript</title>
      <dc:creator>sagar</dc:creator>
      <pubDate>Sun, 30 Jun 2024 16:38:52 +0000</pubDate>
      <link>https://dev.to/sagar7170/-and-difference-in-javascript-44c1</link>
      <guid>https://dev.to/sagar7170/-and-difference-in-javascript-44c1</guid>
      <description>&lt;p&gt;In javascript both “==” and “===” used for comparison but they have purposes and behaviors&lt;/p&gt;

&lt;h2&gt;
  
  
  == (Double equal)
&lt;/h2&gt;

&lt;p&gt;:&lt;br&gt;
The == operator is used for loose equality comparison . When we compare with == it will only compare values not the data type means if we compare string of “5” and integer 5 the result will be true&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(5=="5") //  true
console.log(5==5) //  true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. === (triple equal):
&lt;/h2&gt;

&lt;p&gt;The === operator is used for strict equality comparison. As we studied == only compare values not data type but === compare both values and datatype means if we compare string of “5” and integer 5 the result will be false both values and data type must same&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(5=="5") //  false
console.log(5==5) //  true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Common JavaScript "event Handler" Mistake</title>
      <dc:creator>sagar</dc:creator>
      <pubDate>Tue, 25 Jun 2024 14:32:34 +0000</pubDate>
      <link>https://dev.to/sagar7170/common-javascript-event-handler-mistake-38ce</link>
      <guid>https://dev.to/sagar7170/common-javascript-event-handler-mistake-38ce</guid>
      <description>&lt;p&gt;When i was dealing javacript click event i was doing this mistake see the blow javascript &amp;amp; jquery code snippet&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;javascript code example&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;let name = 'herry';

document.getElementbByClassName('demo').addEventListener('click',function(){
  name = "joy";
})

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;jquery code example&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;let name = 'herry';

$('.demo').on('click',function(){
  name = "joy";
})

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

&lt;/div&gt;



&lt;p&gt;Both javascript &amp;amp; jquery code are same&lt;/p&gt;

&lt;h2&gt;
  
  
  Mistake i was doing
&lt;/h2&gt;

&lt;p&gt;I was trying to update and access it ‘name’ variable after click event triggered as you can see in the above code&lt;br&gt;
when console.log(name) outside the click variable name printed as herry but it was supposed to be as joy&lt;/p&gt;
&lt;h2&gt;
  
  
  Why name Doesn't Update Immediately
&lt;/h2&gt;

&lt;p&gt;The behavior of the click event is asynchronous due to this behavior the code lines executed as&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;let name = ‘herry’;&lt;/li&gt;
&lt;li&gt;console.log(name);&lt;/li&gt;
&lt;li&gt;$(‘.demo’).on(‘click’,function(){
name = “joy”; })&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Order of Execution&lt;/strong&gt;: JavaScript executes the code sequentially from top to bottom. When console.log(a); is executed, the click event hasn't happened yet, so name is still 'herry'.&lt;br&gt;
&lt;strong&gt;Asynchronous Event Handling&lt;/strong&gt;: The click event handler is an asynchronous operation. It only runs when the user clicks on the element with class .demo. Until the click event happens, the code inside the event handler does not run.&lt;/p&gt;

&lt;p&gt;If you want to see the updated value of a after the click event, you should log a inside the click handler:&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 = 'herry';

$('.demo').on('click',function(){
  name = "joy";
 console.log(name) // joy
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;another way&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 = 'herry';

$('.demo').on('click',function(){
  name = "joy";
  UpdateValue(name);
})
function UpdateValue(name){
  console.log(name) // joy
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>jquery</category>
      <category>programming</category>
      <category>coding</category>
    </item>
    <item>
      <title>What is Adobe Experience Manager(AEM) &amp; it's Features</title>
      <dc:creator>sagar</dc:creator>
      <pubDate>Fri, 21 Jun 2024 17:24:56 +0000</pubDate>
      <link>https://dev.to/sagar7170/what-is-adobe-experience-manageraem-its-features-3091</link>
      <guid>https://dev.to/sagar7170/what-is-adobe-experience-manageraem-its-features-3091</guid>
      <description>&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%2Fmh980gp46ik8rom3md55.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%2Fmh980gp46ik8rom3md55.png" alt="Image description" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Adobe experience manager(AEM) is a content management systems(CMS)&lt;br&gt;
for building website , mobile aaps , forms . It enables organizations to create, manage, and deliver digital experiences across various channels, ensuring consistency and relevance.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Key features
&lt;/h2&gt;

&lt;p&gt;*&lt;em&gt;Content Management *&lt;/em&gt;: AEM Provides powerful tools for creating , editing and managing web content. It allows content authors to build and update websites with a WYSIWYG editor, without needing extensive technical knowledge.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Digital Asset Management(DAM)&lt;/strong&gt;: AEM include DAM system for managing rich media like images , videos , documents.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Multi-site Management&lt;/strong&gt;: AEM support managing multiple websites from a single platform. It allows for content reuse, localization, and regionalization, making it easier to maintain consistency across global sites.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Responsive Design&lt;/strong&gt;: AEM provides tools for creating responsive and adaptive designs, ensuring that websites look and function well on various devices and screen sizes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Forms and Documents&lt;/strong&gt;: AEM Forms enables the creation and management of forms and documents, supporting use cases like applications, surveys, and customer correspondence.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Commerce Integration&lt;/strong&gt;: AEM integrates with e-commerce platforms to deliver personalized and consistent shopping experiences across all digital touchpoints.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Extensibility&lt;/strong&gt;: AEM is highly extensible, allowing developers to create custom components, templates, and services. It supports integration with third-party systems through APIs and connectors.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use Cases for AEM
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Corporate Websites&lt;/strong&gt;: AEM is used to build and manage large corporate websites that require frequent updates, localization, and integration with marketing tools.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;E-commerce&lt;/strong&gt;: Online retailers use AEM to deliver personalized shopping experiences, integrate with back-end systems, and manage digital assets.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Government Portals&lt;/strong&gt;: Government agencies use AEM for managing large volumes of content, ensuring accessibility, and delivering services to citizens.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Media and Entertainment&lt;/strong&gt;: Media companies use AEM to manage digital assets, streamline content workflows, and deliver engaging multimedia experiences.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Financial Services&lt;/strong&gt;: Banks and financial institutions use AEM to create secure, compliant, and personalized digital experiences for customers.&lt;/p&gt;

</description>
      <category>aem</category>
      <category>webdev</category>
    </item>
    <item>
      <title>What is CMS (Content Management System)?</title>
      <dc:creator>sagar</dc:creator>
      <pubDate>Fri, 21 Jun 2024 08:07:19 +0000</pubDate>
      <link>https://dev.to/sagar7170/what-is-cms-content-management-system-4077</link>
      <guid>https://dev.to/sagar7170/what-is-cms-content-management-system-4077</guid>
      <description>&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%2Fvir8cqxg2ld0vkfdyigm.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%2Fvir8cqxg2ld0vkfdyigm.png" alt="Image description" width="650" height="394"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A content management system (CMS) is a software application used to create , manage and publish digital content . It is typically used for websites and can be used to manage a wide variety of content, including text, images, videos, and audio.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;CMS's come in many different forms, from open-source platforms like WordPress, Drupal, and Joomla, to proprietary systems like Adobe Experience Manager and Sitecore. Some CMSs are geared towards specific industries or use cases, such as e-commerce, while others are more general-purpose.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Importance of CMS
&lt;/h2&gt;

&lt;p&gt;A Content Management System (CMS) significantly streamlines and accelerates the process of website creation. Without a CMS, developers must manually write and manage extensive HTML, CSS, and JavaScript code. In contrast, a CMS provides built-in components such as responsive headers, text sections, images, and footers, which can be easily added through a simple drag-and-drop interface. This not only eliminates the need for extensive coding but also empowers individuals with minimal or no technical expertise to create, edit, and publish websites efficiently.&lt;/p&gt;

&lt;p&gt;One of the main advantages of using a CMS is that it allows non-technical users to create and manage content without needing to know how to code. This means that content can be updated quickly and easily, without the need for a developer to make changes. Additionally, CMSs often include built-in SEO features to help content rank better in search engine results.&lt;/p&gt;

&lt;p&gt;CMSs also provide various ways to customize the design and functionality of the website, by using template, theme, plugin, and customizing the code, it also allows for easy integration with other tools like analytics, CRM, and marketing automation platforms.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&amp;gt; In summary, A CMS is a powerful tool for creating and managing digital content, and it can be used to improve the efficiency and effectiveness of website content creation and publishing.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
    </item>
    <item>
      <title>Clousers in Javascript?</title>
      <dc:creator>sagar</dc:creator>
      <pubDate>Fri, 21 Jun 2024 06:49:15 +0000</pubDate>
      <link>https://dev.to/sagar7170/clousers-in-javascript-3bc6</link>
      <guid>https://dev.to/sagar7170/clousers-in-javascript-3bc6</guid>
      <description>&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%2Fyracevg2u6lq9f86n376.jpg" 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%2Fyracevg2u6lq9f86n376.jpg" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a closure?
&lt;/h2&gt;

&lt;p&gt;A closure is a feature in JavaScript where an inner function has access to the outer (enclosing) function’s variables&lt;/p&gt;

&lt;p&gt;_&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“A closure is the combination of a function bundled together (enclosed) with references to its surrounding state (the lexical environment). In other words, a closure gives you access to an outer function’s scope from an inner function.”&lt;br&gt;
_&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function outer() {
  var count = 0;

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

  return inner;
}

var counter = outer();

counter(); // 1
counter(); // 2
counter(); // 3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code&lt;/p&gt;

&lt;p&gt;The inner function will have access to the variables in the outer function scope, even after the outer function has returned.&lt;/p&gt;

&lt;p&gt;even after outer function done executing the inner function can have access to outer function variable means when we return inner function the inner function return with its surrounding variable and this is called closures.&lt;/p&gt;

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