<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[AyushCode]]></title><description><![CDATA[AyushCode]]></description><link>https://blog.ayushcode.me</link><image><url>https://cdn.hashnode.com/res/hashnode/image/upload/v1593680282896/kNC7E8IR4.png</url><title>AyushCode</title><link>https://blog.ayushcode.me</link></image><generator>RSS for Node</generator><lastBuildDate>Wed, 07 Oct 2026 19:34:40 GMT</lastBuildDate><atom:link href="https://blog.ayushcode.me/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Template Literals in JavaScript Explained with Examples]]></title><description><![CDATA[Before we know what template literals are, it is important to know why template literals were introduced and what was used before template literals was introduced. What were the problems with the earl]]></description><link>https://blog.ayushcode.me/template-literals-in-javascript-explained-with-examples</link><guid isPermaLink="true">https://blog.ayushcode.me/template-literals-in-javascript-explained-with-examples</guid><category><![CDATA[template literals]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[js]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[webdev]]></category><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><dc:creator><![CDATA[Ayush Kumar]]></dc:creator><pubDate>Fri, 19 Jun 2026 15:38:35 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6957b06e6e38b6011157e5c8/02ffc1fd-9be9-4a5c-8edb-1d2d55250d78.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Before we know what template literals are, it is important to know why template literals were introduced and what was used before template literals was introduced. What were the problems with the earlier method? Let's first discuss that.</p>
<h2>Why Template Literals was introduced?</h2>
<p>Before template literals was introduced, developers used the <code>+</code> operator to join strings.</p>
<pre><code class="language-javascript">let name = "Ayush";

console.log("Name: "+ name);
//Output --  Name: Ayush
</code></pre>
<h2>Problems with <code>+</code> Operator</h2>
<h3>1. Poor Readability</h3>
<p>As strings become longer, concatenation becomes messy.</p>
<pre><code class="language-javascript">const text =
  "Hello " +
  name +
  ", welcome to our website. Your account balance is " +
  balance +
  " rupees.";
</code></pre>
<h3>2. Multi Line string</h3>
<p>before Template Literals</p>
<pre><code class="language-javascript">const message =
  "Line 1\n" +
  "Line 2\n" +
  "Line 3";
</code></pre>
<p>we had to use /n for every line.</p>
<h3>3. Easy to make mistakes</h3>
<p>missing spaces</p>
<pre><code class="language-javascript">let name = "Ayush"
console.log("Hello" + name)
//Output -- HelloAyush
</code></pre>
<p>these types of mistakes were very common</p>
<h2>What are Template Literals?</h2>
<p>Template literals were introduced with ES6 in 2015.</p>
<p>Now instead of ( ' ' ) and ( " " ) back ticks ( ` ` ) are used to define a string and this allowed writing a variable inside a string ( string interpolation) without using the operator.</p>
<img src="https://cdn.hashnode.com/uploads/covers/6957b06e6e38b6011157e5c8/956bb7cc-b4e0-476c-8fce-da7d7a403ddf.png" alt="" style="display:block;margin:0 auto" />

<pre><code class="language-javascript">const name = "Ayush";

const message = `Hello ${name}`;

console.log(message);

//Output -- Hello Ayush
</code></pre>
<h3>Syntax of template literals</h3>
<p>Basic syntax</p>
<pre><code class="language-javascript">`Text here`
</code></pre>
<p>With variable</p>
<pre><code class="language-javascript">const language = "JavaScript";

console.log(`I am learning ${language}`);

//Output -- I am learning JavaScript
</code></pre>
<h3>Multi Line String</h3>
<p>template literals allow you to write multi-line strings directly.</p>
<p>Without Template Literals:</p>
<pre><code class="language-javascript">const text =
  "Hello\n" +
  "Welcome\n" +
  "To JavaScript";
</code></pre>
<p>With Template Literals:</p>
<pre><code class="language-javascript">const text = `
Hello
Welcome
To JavaScript
`;
</code></pre>
<h2>Real-World use cases</h2>
<h3>Generating Dynamic Messages</h3>
<pre><code class="language-javascript">const username = "Ayush";

const greeting = Welcome back, ${username}!;
</code></pre>
<h3>Building URLs</h3>
<pre><code class="language-javascript">const userId = 123;

const url = /users/${userId};
</code></pre>
<h3>Dynamic CSS Classes</h3>
<pre><code class="language-javascript">const active = true;

const className = `btn ${active ? "active" : ""}`;
</code></pre>
<p>Used extensively in React.</p>
<h2>Key Takeaways</h2>
<ul>
<li><p>Template literals were introduced in ES6.</p>
</li>
<li><p>They use backticks ( ` ` ) instead of quotes.</p>
</li>
<li><p><code>${}</code> allows string interpolation.</p>
</li>
<li><p>They improve readability compared to <code>+</code> concatenation.</p>
</li>
<li><p>Multi-line strings become much easier to write.</p>
</li>
<li><p>Widely used in React, URLs, and dynamic UI rendering.</p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Top JavaScript Array Methods Every Beginner Should Know]]></title><description><![CDATA[When I first started learning JavaScript, I felt array methods were quite confusing, as there were many of them. But after practicing with some examples, I realised that array methods makes the code v]]></description><link>https://blog.ayushcode.me/top-javascript-array-methods-every-beginner-should-know</link><guid isPermaLink="true">https://blog.ayushcode.me/top-javascript-array-methods-every-beginner-should-know</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[coding]]></category><category><![CDATA[webdevelopment]]></category><category><![CDATA[Programming Blogs]]></category><category><![CDATA[array]]></category><category><![CDATA[array methods]]></category><category><![CDATA[#learning-in-public]]></category><dc:creator><![CDATA[Ayush Kumar]]></dc:creator><pubDate>Sat, 06 Jun 2026 10:37:29 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6957b06e6e38b6011157e5c8/feca6202-9a45-4100-95d8-cf805026ce1c.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When I first started learning JavaScript, I felt array methods were quite confusing, as there were many of them. But after practicing with some examples, I realised that array methods makes the code very cleaner and readable.</p>
<p>In this blog, we will learn the important Javascript array methods that are used most of the time.</p>
<h2>Why do We Need Array Method?</h2>
<p>Without array methods, If we need to perform operations on a particular or all the elements of an array, we will have to use a for loop:</p>
<p>For example:</p>
<pre><code class="language-javascript">let arr = [1, 2, 3, 4];
for (let i = 0; i &lt; arr.length; i++) {
  arr[i] *= 2;
}

console.log(arr);  // Output : [2, 4, 6, 8]
</code></pre>
<p>This works, but array methods are very much shorter, cleaner, and more readable.</p>
<h2>1. push() and pop() :-</h2>
<ul>
<li><p>Both are used to manipulate the data at the end of an array. They <strong>mutates the original array</strong></p>
</li>
<li><p>push() is used to add an element at the last of an array.</p>
</li>
<li><p>pop() is used to remove an element from the last of an array.</p>
</li>
</ul>
<p>For Example:</p>
<pre><code class="language-javascript">//Push.....

const fruits = ["apple", "banana"]; 
fruits.push("mango"); 
console.log(fruits);

// Output : ["apple", "banana", "mango"]

//Pop.....

fruits.pop();
console.log(fruits);

// Output : ["apple", "banana",]
</code></pre>
<h2>2. shift() and unshift() :-</h2>
<ul>
<li><p>Both are used to manipulate the data at the beginning of an array. they <strong>mutate the original array</strong></p>
</li>
<li><p>shift() is used to add an element at the start of an array.</p>
</li>
<li><p>unshift() is used to remove an element from the start of an array (first element).</p>
</li>
</ul>
<p>For Example:</p>
<pre><code class="language-javascript">//shift().....

const fruits = ["apple", "banana"]; 
fruits.shift("mango"); 
console.log(fruits);

// Output : ["mango", "apple", "banana"]

//unshift.....

fruits.pop();
console.log(fruits);

// Output : ["apple", "banana"]
</code></pre>
<h2>3. map() :-</h2>
<p>Map is used to mutate every element of an array, for example, doubling each element of the array, etc</p>
<p>Map <strong>returns a brand new array</strong> consisting of the elements which result from the calling of the callback function for each element in the original array</p>
<p>For Example:</p>
<pre><code class="language-javascript">const arr = [1, 2, 3, 4];

const doubled = arr.map(function (num) {
  return num * 2;
});

console.log(doubled);

//Output: [2, 4, 6, 8]
</code></pre>
<h2>4. filter() :-</h2>
<p>As the name suggests, it is used to filter the elements of on array based on a given condition. It <strong>returns a brand new array</strong> consisting of the elements that satisfied a given condition.</p>
<p>For Example:</p>
<pre><code class="language-javascript">
const numbers = [5, 10, 15, 20];

const greaterThanTen = numbers.filter(function (num) {
  return num &gt; 10;
});

console.log(greaterThanTen);




Output

[15, 20]

Visual Flow

 [5, 10, 15, 20]
        ↓
keep numbers &gt; 10
        ↓
    [15, 20]
</code></pre>
<h2>5. reduce() :-</h2>
<ul>
<li><p><code>reduce()</code> is used to combine all array values into a single value.</p>
</li>
<li><p>It may feel confusing at first, so start with simple examples.</p>
</li>
</ul>
<p>Example: Find Sum of Numbers</p>
<pre><code class="language-javascript">const numbers = [1, 2, 3, 4];

const total = numbers.reduce(function (accumulator, currentValue) {
  return accumulator + currentValue;
}, 0);

console.log(total);
</code></pre>
<p>Output</p>
<pre><code class="language-plaintext">10
</code></pre>
<h3>How reduce() Works</h3>
<pre><code class="language-plaintext">0 + 1 = 1
1 + 2 = 3
3 + 3 = 6
6 + 4 = 10
</code></pre>
<p>Final Answer = <code>10</code></p>
<h2>6. forEach :-</h2>
<ul>
<li><p>forEach() is used to loop over each element of an array and perform the required action.</p>
</li>
<li><p>Unlike map, it does not return anything.</p>
</li>
</ul>
<p>Example</p>
<pre><code class="language-javascript">const fruits = ["apple", "banana", "mango"];

fruits.forEach(function (fruit) {
  console.log(fruit);
});

// Output

apple
banana
mango
</code></pre>
<p>Use <code>forEach()</code> when you only want to perform actions like printing values.</p>
<h2>Small Practice Assignment</h2>
<p>Try this yourself in the browser console.</p>
<p>Step 1: Create an array</p>
<pre><code class="language-javascript">const numbers = [2, 5, 8, 12];
</code></pre>
<p>Step 2: Double each number using map()</p>
<pre><code class="language-javascript">const doubled = numbers.map((num) =&gt; num * 2);

console.log(doubled);
</code></pre>
<p>Step 3: Get numbers greater than 10 using filter()</p>
<pre><code class="language-javascript">const greaterThanTen = numbers.filter((num) =&gt; num &gt; 10);

console.log(greaterThanTen);
</code></pre>
<p>Step 4: Find total sum using reduce()</p>
<pre><code class="language-javascript">const total = numbers.reduce((acc, curr) =&gt; acc + curr, 0);

console.log(total);
</code></pre>
<hr />
<h2>Final Thoughts</h2>
<p>Array methods are extremely useful in JavaScript in modern web development.</p>
<p>At first, reduce() and filter() might feel a little difficult, but after practicing a few examples, it will become much easier</p>
<p>The more you practice, the more natural these methods will feel.</p>
<p>Happy Coding</p>
]]></content:encoded></item></channel></rss>