<?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: Sujit Kar</title>
    <description>The latest articles on DEV Community by Sujit Kar (@sujitkar1195).</description>
    <link>https://dev.to/sujitkar1195</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%2F1211792%2F158ab95a-9fa6-4550-bbc9-3f1016521d04.jpeg</url>
      <title>DEV Community: Sujit Kar</title>
      <link>https://dev.to/sujitkar1195</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sujitkar1195"/>
    <language>en</language>
    <item>
      <title>Why n=0 is falsy but n = new Number(0) is truthy In Javascript ?</title>
      <dc:creator>Sujit Kar</dc:creator>
      <pubDate>Wed, 29 Nov 2023 11:41:07 +0000</pubDate>
      <link>https://dev.to/sujitkar1195/why-n0-is-falsy-but-n-new-number0-is-truthy-in-javascript--2bg4</link>
      <guid>https://dev.to/sujitkar1195/why-n0-is-falsy-but-n-new-number0-is-truthy-in-javascript--2bg4</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let n = 0;
if (n) console.log("Truthy");
else console.log("Falsy"); // It print "Falsy"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Okay fine. But what wrong in the below code?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let n = new Number(0);
if (n) console.log("Truthy"); // it print "Truthy".
else console.log("Falsy");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The answer is very &lt;em&gt;simple&lt;/em&gt;.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's check data type of the variables.
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let n = 0;
console.log(typeof n); It print "number"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let n = new Number(0);
console.log(typeof n); It print "object"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Did you get your answer?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;It is happening because of data type is differnt.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Thank You,&lt;br&gt;
&lt;a class="mentioned-user" href="https://dev.to/sujitkar1195"&gt;@sujitkar1195&lt;/a&gt; &lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to check Javascript object is empty or not?</title>
      <dc:creator>Sujit Kar</dc:creator>
      <pubDate>Sat, 18 Nov 2023 10:26:54 +0000</pubDate>
      <link>https://dev.to/sujitkar1195/how-to-check-the-javscript-object-is-empty-or-not-476j</link>
      <guid>https://dev.to/sujitkar1195/how-to-check-the-javscript-object-is-empty-or-not-476j</guid>
      <description>&lt;p&gt;This is tricky but not difficult.&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 = {};
if( ( Object.keys(obj) ).length === 0){
 console.log("Object is empty");
}
else{
 console.log("Object is not empty");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How this works?
&lt;/h2&gt;

&lt;p&gt;Because, with the help of keys property of the &lt;em&gt;Object class&lt;/em&gt; it creates an array of keys of obj. And the array has length property to find its length. If length is 0 then the obj is empty otherwise not.&lt;/p&gt;

&lt;p&gt;If any doubts kindly ask me.&lt;/p&gt;

&lt;p&gt;Thanks!!!&lt;br&gt;
&lt;a class="mentioned-user" href="https://dev.to/sujitkar1195"&gt;@sujitkar1195&lt;/a&gt; &lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to check an Array is empty or not in Javascript?</title>
      <dc:creator>Sujit Kar</dc:creator>
      <pubDate>Sat, 18 Nov 2023 10:17:45 +0000</pubDate>
      <link>https://dev.to/sujitkar1195/how-to-check-an-array-is-empty-or-not-in-javascript-3p4p</link>
      <guid>https://dev.to/sujitkar1195/how-to-check-an-array-is-empty-or-not-in-javascript-3p4p</guid>
      <description>&lt;p&gt;There is a very simple technique to check whether an array is empty or not.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const arr = [];
if(arr.length === 0){
 console.log("Array is empty");
}
else{
 console.log("Array is not empty");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Get in touch with me.&lt;/p&gt;

&lt;p&gt;Thanks!!!&lt;br&gt;
&lt;a class="mentioned-user" href="https://dev.to/sujitkar1195"&gt;@sujitkar1195&lt;/a&gt; &lt;/p&gt;

</description>
    </item>
    <item>
      <title>What is the global scope pollution ?</title>
      <dc:creator>Sujit Kar</dc:creator>
      <pubDate>Sat, 18 Nov 2023 03:59:58 +0000</pubDate>
      <link>https://dev.to/sujitkar1195/what-is-the-global-scope-pollution--18n8</link>
      <guid>https://dev.to/sujitkar1195/what-is-the-global-scope-pollution--18n8</guid>
      <description>&lt;h2&gt;
  
  
  Definition:
&lt;/h2&gt;

&lt;p&gt;Global function pollution in JavaScript refers to the act of declaring functions in the global scope, which can lead to a number of problems.&lt;/p&gt;

&lt;h2&gt;
  
  
  First:
&lt;/h2&gt;

&lt;p&gt;It can make code difficult to read and understand. When functions are declared in the &lt;em&gt;global scope&lt;/em&gt;, they can be called from anywhere in the code, which can make it difficult to track where they are being used and what they are doing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Second:
&lt;/h2&gt;

&lt;p&gt;It can lead to name &lt;em&gt;collisions&lt;/em&gt;.If two functions have the same name, the JavaScript engine will only be able to use one of them, which can lead to unexpected behavior.&lt;/p&gt;

&lt;h2&gt;
  
  
  Third:
&lt;/h2&gt;

&lt;p&gt;It can make code difficult to test. When functions are declared in the global scope, they can be difficult to isolate and test in a controlled environment.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to avoid Global namespace pollution:
&lt;/h2&gt;

&lt;p&gt;To avoid global namespace pollution, it is generally best to use functions and modules to encapsulate code. This will help to keep the global scope clean and organized, and will make it easier to find and fix bugs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Here are some tips to avoid global scope pollution in JavaScript:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Use functions and modules to encapsulate code.&lt;/li&gt;
&lt;li&gt;Avoid using global variables unless absolutely necessary.&lt;/li&gt;
&lt;li&gt;Use descriptive variable and function names.&lt;/li&gt;
&lt;li&gt;Use comments to document your code.&lt;/li&gt;
&lt;li&gt;Use a linter to help you identify potential problems.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By following these tips, you can help to keep your JavaScript code clean and organized, and make it easier to read, maintain, and debug.&lt;/p&gt;

&lt;p&gt;Thanks!!!&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
