<?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: Samarthya</title>
    <description>The latest articles on DEV Community by Samarthya (@sama_rthya).</description>
    <link>https://dev.to/sama_rthya</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1025148%2F7ad40017-ad48-4e76-a94f-8eaca36c92d3.jpg</url>
      <title>DEV Community: Samarthya</title>
      <link>https://dev.to/sama_rthya</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sama_rthya"/>
    <language>en</language>
    <item>
      <title>The Power of Closures in JavaScript: A Beginner's Guide</title>
      <dc:creator>Samarthya</dc:creator>
      <pubDate>Sun, 12 Feb 2023 16:33:44 +0000</pubDate>
      <link>https://dev.to/sama_rthya/the-power-of-closures-in-javascript-a-beginners-guide-478h</link>
      <guid>https://dev.to/sama_rthya/the-power-of-closures-in-javascript-a-beginners-guide-478h</guid>
      <description>&lt;p&gt;Say goodbye to messy code and hello to organized, secure, and maintainable solutions with Closures.&lt;/p&gt;

&lt;p&gt;Explained With real life example - Chef Secrets. 👨‍🍳 &lt;br&gt;
&lt;strong&gt;Code example below:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;But first of all what is closures ?&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A closure in JavaScript is a function that has access to variables in its outer scope even after the function has completed its execution.&lt;/p&gt;

&lt;p&gt;Now its hard to fully understand with only one line definition so&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Time for a real life example..&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Think of Closures as a chef and their kitchen secrets.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iGrdx1He--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6xilxd7bnspl71io8pfc.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iGrdx1He--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6xilxd7bnspl71io8pfc.jpg" alt="Image description" width="880" height="1327"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A basic function could reveal a simple recipe, &lt;/p&gt;

&lt;p&gt;but what if the chef wants to keep certain ingredients or cooking methods a secret?&lt;/p&gt;

&lt;p&gt;This is where Closures come in. &lt;/p&gt;

&lt;p&gt;The chef can use closures to wrap up their secret ingredients or methods, creating a "closed-off" environment that can only be accessed by specific functions.&lt;/p&gt;

&lt;p&gt;Just like a chef's secret recipe, a closure in JavaScript allows us to keep variables and functions private, only accessible within the closure scope.&lt;/p&gt;

&lt;p&gt;This can help us manage state and make our code more organized, secure, and maintainable.&lt;/p&gt;

&lt;p&gt;Just like a chef's kitchen, closures provide a neat and organized way to handle our code and make it work the way we want it to.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hkA5yd-d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ed0w00ic9jeakwm37yyt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hkA5yd-d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ed0w00ic9jeakwm37yyt.png" alt="Image description" width="880" height="515"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>The Sweetest Way To Learn Higher-Order Functions In JavaScript With Ice cream</title>
      <dc:creator>Samarthya</dc:creator>
      <pubDate>Sun, 12 Feb 2023 04:56:23 +0000</pubDate>
      <link>https://dev.to/sama_rthya/the-sweetest-way-to-learn-higher-order-functions-in-javascript-with-ice-cream-337o</link>
      <guid>https://dev.to/sama_rthya/the-sweetest-way-to-learn-higher-order-functions-in-javascript-with-ice-cream-337o</guid>
      <description>&lt;p&gt;Let's Learn About Higher-Order Functions in JavaScript with Ice Cream 🍦&lt;br&gt;
Have you heard of Higher-Order Functions in JavaScript?&lt;br&gt;
They're pretty cool and can make your code more flexible and reusable.&lt;/p&gt;

&lt;p&gt;But what exactly are Higher-Order Functions?&lt;br&gt;
Simply put, they're functions that take another function as an argument or return a function as a result.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Confused?&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;Let's break it down with a sweet example.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6mtz97ar9cpntd3w4r5q.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6mtz97ar9cpntd3w4r5q.jpg" alt="Image description" width="800" height="1200"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Imagine..&lt;br&gt;
You want to make different flavors of ice cream for your friends.&lt;/p&gt;

&lt;p&gt;A basic function could make one specific flavor.&lt;br&gt;
But what if you want to mix things up and make each friend a unique flavor with different toppings? &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This is where Higher-Order Functions come in.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Think of a Higher-Order Function like an ice cream shop. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyvsv0h0istgu11ymou35.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyvsv0h0istgu11ymou35.jpg" alt="Image description" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can order any flavor you want and the shop will use different functions to make it based on your chosen ingredients and toppings.&lt;br&gt;
So each of your friends gets a custom-made, one-of-a-kind ice cream!&lt;/p&gt;

&lt;h2&gt;
  
  
  Now some examples of Higher-Order Functions with some more real life examples
&lt;/h2&gt;

&lt;p&gt;🔶️&lt;strong&gt;map()&lt;/strong&gt; - A function that takes an array and a callback function as arguments and returns a new array with the results of calling the callback function on each element of the original array.&lt;/p&gt;

&lt;p&gt;🔸️&lt;em&gt;&lt;strong&gt;Real life equivalent&lt;/strong&gt;&lt;/em&gt;: "map()" is like a chef in a kitchen, who takes a recipe and ingredients, and creates a dish.&lt;/p&gt;

&lt;p&gt;🔸️&lt;em&gt;*&lt;em&gt;Code Example *&lt;/em&gt;&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmd7koko1ns3c9pfj3grl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmd7koko1ns3c9pfj3grl.png" alt="Image description" width="800" height="523"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🔶️&lt;strong&gt;filter()&lt;/strong&gt; - A function that takes an array and a callback function as arguments and returns a new array with only the elements that pass a certain test specified in the callback function. &lt;/p&gt;

&lt;p&gt;🔸️&lt;em&gt;&lt;strong&gt;Real life equivalent:&lt;/strong&gt;&lt;/em&gt; "filter()" is like a sifter, who separates the desired elements from a pile of items.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Code Example:&lt;/strong&gt;&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2hwqgdq5ipd98yyxzsef.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2hwqgdq5ipd98yyxzsef.png" alt="Image description" width="800" height="548"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🔶️&lt;strong&gt;reduce()&lt;/strong&gt; - A function that takes an array, a callback function, and an accumulator as arguments and returns a single value that is the result of successively combining elements of the array using the callback function.&lt;/p&gt;

&lt;p&gt;🔸️ &lt;em&gt;&lt;strong&gt;Real life equivalent:&lt;/strong&gt;&lt;/em&gt; "reduce()" is like a cashier, who adds up the total cost of items in a shopping cart.&lt;br&gt;
&lt;em&gt;&lt;strong&gt;Code Example:&lt;/strong&gt;&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frtuyihzbfyd4djsf91fe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frtuyihzbfyd4djsf91fe.png" alt="Image description" width="800" height="608"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🔶️ &lt;strong&gt;sort()&lt;/strong&gt; - A function that takes an array and returns a new array with the elements sorted in a specific order.&lt;/p&gt;

&lt;p&gt;🔸️&lt;em&gt;&lt;strong&gt;Real life equivalent:&lt;/strong&gt;&lt;/em&gt; "sort()" is like an organizer, who arranges items in a specific order.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Code Example:&lt;/strong&gt;&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fma0qfytfb53psfgl5aav.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fma0qfytfb53psfgl5aav.png" alt="Image description" width="800" height="667"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🔶️&lt;strong&gt;forEach()&lt;/strong&gt; - A function that takes an array and a callback function as arguments and executes the callback function on each element of the array.&lt;/p&gt;

&lt;p&gt;🔸️&lt;strong&gt;_Real life equivalent: _&lt;/strong&gt;"forEach()" is like a delivery person, who delivers packages to each address on a list.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Code Example:&lt;/strong&gt;&lt;/em&gt;:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa2yfg4vuo4j8rok0t9lj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa2yfg4vuo4j8rok0t9lj.png" alt="Image description" width="800" height="988"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Using Higher-Order Functions allows you to create multiple versions of a component with different data, making your code neater and easier to maintain. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Plus, it makes your code more flexible and reusable.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;But  keep in mind that Higher-Order Functions can be a bit more complex than basic functions, so you may need to do some extra studying to fully utilize their potential. &lt;/p&gt;

&lt;p&gt;But trust me,learning about Higher Order Function in the JavaScript is worth it.&lt;/p&gt;

</description>
      <category>vue</category>
      <category>webassembly</category>
      <category>rust</category>
      <category>learning</category>
    </item>
  </channel>
</rss>
