<?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: snangunurikrishna</title>
    <description>The latest articles on DEV Community by snangunurikrishna (@snangunurikrishna).</description>
    <link>https://dev.to/snangunurikrishna</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%2F602468%2F9fcf9f11-f9fe-4fdf-a282-a18be3dee319.png</url>
      <title>DEV Community: snangunurikrishna</title>
      <link>https://dev.to/snangunurikrishna</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/snangunurikrishna"/>
    <language>en</language>
    <item>
      <title>Part 1 of 3 TypeScript Tricks I wish I knew when I started learning TypeScript</title>
      <dc:creator>snangunurikrishna</dc:creator>
      <pubDate>Sun, 25 Jun 2023 18:57:40 +0000</pubDate>
      <link>https://dev.to/snangunurikrishna/part-1-of-3-typescript-tricks-i-wish-i-knew-when-i-started-learning-typescript-354n</link>
      <guid>https://dev.to/snangunurikrishna/part-1-of-3-typescript-tricks-i-wish-i-knew-when-i-started-learning-typescript-354n</guid>
      <description>&lt;h1&gt;
  
  
  Trick 1:
&lt;/h1&gt;

&lt;p&gt;I noticed the message 'unexpected any' when using eslint with TypeScript. It made me wonder why 'any' is considered bad. How should I declare a variable that can hold any possible value? Let's examine 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 someArray: Array&amp;lt;any&amp;gt; = [];

// add some values
someArray.push(1);
someArray.push("Hello");
someArray.push({ age: 42 });
someArray.push(null);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We're constructing an array capable of containing all possible types. Although it may not be the most optimal code, let's proceed with it. We're including a number, a string, and an object. Now, let's examine the following code and check its outcome.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const someArray: Array&amp;lt;any&amp;gt; = [];

// ... adding the values
someArray.forEach(entry =&amp;gt; {
  console.log(entry.age);
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code is considered valid TypeScript and compiles successfully. However, it will encounter a runtime failure. The reason being, when we iterate over an entry that is &lt;code&gt;null&lt;/code&gt;or &lt;code&gt;undefined&lt;/code&gt;, and subsequently attempt to access the &lt;code&gt;.age&lt;/code&gt; property, it will result in an error being thrown, as exemplified by the following message:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Uncaught TypeError: Cannot read properties of null.&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I think this is some kind of false security because you expect things to just work. After all the TS compiler told you the code is fine.&lt;/p&gt;

&lt;p&gt;But we can fix this! And the change is actually super simple. Instead of typing the array as Arraywe can just use Array if we now use the same code but with that change it will look like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const someArray: Array&amp;lt;unknown&amp;gt; = [];

// ... adding the values

someArray.forEach(entry =&amp;gt; {
  console.log(entry.age);
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and this code will not compile! Instead, TypeScript shows the following error when we try to access &lt;code&gt;entry.age&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;using &lt;code&gt;unknown&lt;/code&gt; enforces us to check the type (or explicitly casting the value) before we do something with a value with is &lt;code&gt;unknown&lt;/code&gt;. Let's look at 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;// ... other code

type Human = { name: string, age: number };

someArray.forEach(entry =&amp;gt; {
  // if it's an object, we know it's a Human
  if(typeof entry === 'object'){
    console.log((entry as Human).age);
  }
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case we checked whether the value is an object and then access the .age property. And because this is such a abstract topic, here is a little wrap-up:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;any&lt;/code&gt; is basically saying the TypeScript compiler to not check that bit of code. Avoid using any whenever you can! It's better to use &lt;code&gt;unknown&lt;/code&gt; instead because it enforces you to check the type of the value before using it or else it won't compile!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  For more interesting content visit below website
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://fullstackindepth.com/"&gt;https://fullstackindepth.com/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>javascript</category>
      <category>react</category>
      <category>angular</category>
    </item>
    <item>
      <title>How to conditionally adding a key-value pair in object</title>
      <dc:creator>snangunurikrishna</dc:creator>
      <pubDate>Sun, 11 Jun 2023 18:39:40 +0000</pubDate>
      <link>https://dev.to/snangunurikrishna/how-to-conditionally-adding-a-key-value-pair-in-object-lc6</link>
      <guid>https://dev.to/snangunurikrishna/how-to-conditionally-adding-a-key-value-pair-in-object-lc6</guid>
      <description>&lt;p&gt;When initializing a new object in JavaScript, you can efficiently add a key-value pair conditionally by utilizing the concise and expressive nature of the conditional operator.&lt;/p&gt;

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

&lt;p&gt;✅ For more tips &amp;amp; tricks on javascript learn from below website&lt;br&gt;
🎉🎉 &lt;a href="https://fullstackindepth.com/"&gt;https://fullstackindepth.com/&lt;/a&gt; 🎉🎉&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Different ways to check if an array includes a value in javascript 🤔🤔</title>
      <dc:creator>snangunurikrishna</dc:creator>
      <pubDate>Mon, 27 Mar 2023 05:47:25 +0000</pubDate>
      <link>https://dev.to/snangunurikrishna/different-ways-to-check-if-an-array-includes-a-value-in-javascript-4cen</link>
      <guid>https://dev.to/snangunurikrishna/different-ways-to-check-if-an-array-includes-a-value-in-javascript-4cen</guid>
      <description>&lt;h1&gt;
  
  
  𝐉𝐚𝐯𝐚𝐬𝐜𝐫𝐢𝐩𝐭 ✍️ 𝐩𝐨𝐬𝐭 - 8 :
&lt;/h1&gt;

&lt;p&gt;👉 There are several ways to check if an array includes a value in javascript. Here are some of the most common methods. 🤔🤔&lt;/p&gt;

&lt;p&gt;💎 𝐢𝐧𝐝𝐞𝐱𝐎𝐟(): The indexOf() method returns the first index at which the given element can be found in the array. or -1 if not present.&lt;/p&gt;

&lt;p&gt;💎𝐢𝐧𝐜𝐥𝐮𝐝𝐞𝐬(): The includes() method returns a boolean value which indicates whether the element is present in the array or not.&lt;/p&gt;

&lt;p&gt;💎 𝐟𝐢𝐧𝐝(): The find() method will return the value of first element in the array that satisfies the provided condition. If no values satisfies the condition, undefined is returned.&lt;/p&gt;

&lt;p&gt;💎𝐬𝐨𝐦𝐞():The some() method will test whether atleast one element in the array passes the condition. It returns a boolean value.&lt;/p&gt;

&lt;p&gt;All these methods have their own advantages &amp;amp; disadvantages.&lt;br&gt;
💡 The best method to choose will depend on the specific use case.&lt;/p&gt;

&lt;p&gt;Hope this helps ✅ Do Like 👍 &lt;/p&gt;

&lt;p&gt;Follow us on Linkedin:&lt;br&gt;
&lt;a href="https://www.linkedin.com/in/sai-krishna-nangunuri-bba504180"&gt;https://www.linkedin.com/in/sai-krishna-nangunuri-bba504180&lt;br&gt;
&lt;/a&gt;&lt;br&gt;
Follow us on Fb page:&lt;br&gt;
&lt;a href="https://www.facebook.com/profile.php?id=100064154822848"&gt;https://www.facebook.com/profile.php?id=100064154822848&lt;br&gt;
&lt;/a&gt;&lt;br&gt;
Follow us ⚡ for more:&lt;br&gt;
Tips💡+ Guides📜 + Resources 💎 related to Web Development 🧑‍💻&lt;/p&gt;

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

</description>
      <category>javascript</category>
      <category>react</category>
      <category>angular</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to remove a specific item from an array in javascript ?</title>
      <dc:creator>snangunurikrishna</dc:creator>
      <pubDate>Sat, 25 Mar 2023 18:39:58 +0000</pubDate>
      <link>https://dev.to/snangunurikrishna/how-to-remove-a-specific-item-from-an-array-in-javascript--35o9</link>
      <guid>https://dev.to/snangunurikrishna/how-to-remove-a-specific-item-from-an-array-in-javascript--35o9</guid>
      <description>&lt;h1&gt;
  
  
  𝐉𝐚𝐯𝐚𝐬𝐜𝐫𝐢𝐩𝐭 ✍️ 𝐩𝐨𝐬𝐭 - 6 :
&lt;/h1&gt;

&lt;p&gt;👉 There are several ways to remove a specific item from the array in JavaScript. Here are few ways:&lt;/p&gt;

&lt;p&gt;Hope this helps ✅ Do Like 👍&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rgBhMqyy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4zjtly1frns8nr726y5f.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rgBhMqyy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4zjtly1frns8nr726y5f.JPG" alt="Image description" width="739" height="618"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Follow us on Linkedin:&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://www.linkedin.com/in/sai-krishna-nangunuri-bba504180"&gt;https://www.linkedin.com/in/sai-krishna-nangunuri-bba504180&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;&lt;u&gt;Follow us on Fb page:&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://www.facebook.com/profile.php?id=100064154822848"&gt;https://www.facebook.com/profile.php?id=100064154822848&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>frontend</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Part 1: Javascript Basics you MUST know as a developer</title>
      <dc:creator>snangunurikrishna</dc:creator>
      <pubDate>Mon, 12 Apr 2021 08:11:50 +0000</pubDate>
      <link>https://dev.to/snangunurikrishna/part-1-javascript-basics-you-must-know-as-a-developer-43kd</link>
      <guid>https://dev.to/snangunurikrishna/part-1-javascript-basics-you-must-know-as-a-developer-43kd</guid>
      <description>&lt;p&gt;&lt;a href="https://youtu.be/3Z1f_tX4eJ8"&gt;https://youtu.be/3Z1f_tX4eJ8&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>angular</category>
      <category>vue</category>
    </item>
  </channel>
</rss>
