<?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: aniketcodes</title>
    <description>The latest articles on DEV Community by aniketcodes (@aniketcodes).</description>
    <link>https://dev.to/aniketcodes</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%2F525003%2Fdcabb71b-d834-4555-be5e-57a32ab8858d.gif</url>
      <title>DEV Community: aniketcodes</title>
      <link>https://dev.to/aniketcodes</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aniketcodes"/>
    <language>en</language>
    <item>
      <title>The tilde(~) operator: the secret weapon for efficient integer conversion</title>
      <dc:creator>aniketcodes</dc:creator>
      <pubDate>Tue, 20 Dec 2022 05:15:02 +0000</pubDate>
      <link>https://dev.to/aniketcodes/the-tilde-operator-the-secret-weapon-for-efficient-integer-conversion-2028</link>
      <guid>https://dev.to/aniketcodes/the-tilde-operator-the-secret-weapon-for-efficient-integer-conversion-2028</guid>
      <description>&lt;p&gt;In JavaScript, the tilde &lt;code&gt;(~)&lt;/code&gt; is a bitwise &lt;code&gt;NOT&lt;/code&gt; operator. It performs a bitwise NOT operation on its operand, which inverts the bits of the operand.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let x = 5;  // 00000000000000000000000000000101
let y = ~x; // 11111111111111111111111111111010
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's important to note that the bitwise NOT operator only works on integers. If you try to use it on a non-integer value (such as a string or a floating-point number), it will be converted to an integer before the operation is performed.&lt;/p&gt;

&lt;p&gt;The tilde operator can also be used as a shorthand for &lt;code&gt;Math.floor()&lt;/code&gt; to round a number down to the nearest integer. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let x = 5.7;
let y = ~~x;  // y is 5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the double tilde operator &lt;code&gt;~~&lt;/code&gt; rounds the number &lt;code&gt;x&lt;/code&gt; down to the nearest integer, resulting in &lt;code&gt;y&lt;/code&gt; being set to 5. This is equivalent to using the &lt;code&gt;Math.floor()&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;Just be mindful with the size of your integers using the double NOT operator&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// 10 digits
&amp;gt; parseInt(9999999999)
9999999999
&amp;gt; ~~9999999999
1410065407

// 9 digits
&amp;gt; parseInt(999999999)
999999999
&amp;gt; ~~999999999
999999999
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>watercooler</category>
    </item>
    <item>
      <title>The Surprising Power of MongoDB's Limit(0) Method</title>
      <dc:creator>aniketcodes</dc:creator>
      <pubDate>Sat, 17 Dec 2022 18:19:31 +0000</pubDate>
      <link>https://dev.to/aniketcodes/the-surprising-power-of-mongodbs-limit0-method-4nnc</link>
      <guid>https://dev.to/aniketcodes/the-surprising-power-of-mongodbs-limit0-method-4nnc</guid>
      <description>&lt;p&gt;The &lt;code&gt;limit()&lt;/code&gt; method in MongoDB allows you to specify the maximum number of documents that should be returned in a query result. By default, the &lt;code&gt;limit()&lt;/code&gt; method returns all documents in a collection.&lt;br&gt;
But what if you use &lt;code&gt;limit(0)&lt;/code&gt;?&lt;br&gt;
Instead of returning 0 records, it will return all the records present in the collection.&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%2Fi3yj4c5bwnc4os27f3wz.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%2Fi3yj4c5bwnc4os27f3wz.png" alt="Image description" width="370" height="223"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This happens because MongoDB treats 0 in &lt;code&gt;limit()&lt;/code&gt; as &lt;code&gt;infinity&lt;/code&gt;.&lt;/p&gt;

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