<?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: MoreOnFew</title>
    <description>The latest articles on DEV Community by MoreOnFew (@moreonfew).</description>
    <link>https://dev.to/moreonfew</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%2F744801%2Fb7157189-d4e8-4a06-817c-a2af9db03d14.png</url>
      <title>DEV Community: MoreOnFew</title>
      <link>https://dev.to/moreonfew</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/moreonfew"/>
    <language>en</language>
    <item>
      <title>[Solved] Attempted import error: ‘Switch’ is not exported from ‘react-router-dom’</title>
      <dc:creator>MoreOnFew</dc:creator>
      <pubDate>Wed, 16 Feb 2022 07:16:10 +0000</pubDate>
      <link>https://dev.to/moreonfew/solved-attempted-import-error-switch-is-not-exported-from-react-router-dom-565e</link>
      <guid>https://dev.to/moreonfew/solved-attempted-import-error-switch-is-not-exported-from-react-router-dom-565e</guid>
      <description>&lt;p&gt;You might be facing an "&lt;a href="https://www.moreonfew.com/attempted-import-error-switch-is-not-exported-from-react-router-dom/"&gt;Attempted import error: 'Switch' is not exported from 'react-router-dom'&lt;/a&gt; " error if you are using the react-router-dom package version 6. This error is caused due to using the older switch syntax of the react-router-dom. From version 6 onwards, the react-router-dom has replaced “Switch” with “Routes”. Let us take a look at how to solve the ‘Switch’ is not exported from ‘react-router-dom’ error.&lt;/p&gt;

&lt;h2&gt;
  
  
  What causes the ‘Switch’ is not exported from ‘react-router-dom’ error in Reactjs?
&lt;/h2&gt;

&lt;p&gt;As I mentioned earlier, the cause of the ‘Switch’ is not exported from ‘react-router-dom’ error mostly is because you are using v6 or above of react-router-dom whereas the syntax you are using is still the older one. In react-router-dom v6 onwards, the “Switch” is replaced by “Routes”.&lt;/p&gt;

&lt;p&gt;An Example of code that might throw the error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./main.css&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;NavBar&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./components/navbar.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;HomePage&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./components/pages/homepage.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Footer&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./components/footer.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;BrowserRouter&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;Router&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Switch&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Route&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Link&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-router-dom&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Router&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;main-wrapper&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;NavBar&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Switch&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Route&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/home&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;component&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;HomePage&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Switch&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Footer&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Router&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And the package.json might have the following&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nl"&gt;"dependencies"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"react-router-dom"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"^6.2.1"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;Version&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;of&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;React&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mtbm7PrK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.moreonfew.com/wp-content/uploads/2022/02/screenshot-switch-is-not-exported-error.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mtbm7PrK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.moreonfew.com/wp-content/uploads/2022/02/screenshot-switch-is-not-exported-error.png" alt="'Switch' is not exported from 'react-router-dom' error" width="719" height="181"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Screenshot showing ‘Switch’ is not exported from ‘react-router-dom’ error&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In the above code we can notice that the code is using  , whereas the package.json says that we are using v6 of react-router-dom.&lt;/p&gt;

&lt;p&gt;There are 2 ways we can solve the ‘Switch’ is not exported from ‘react-router-dom’ error in ReactJs.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Solution 1 :&lt;/strong&gt; Upgrade the react-router-dom and the related code to the latest version&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Solution 2 :&lt;/strong&gt; Downgrade react-router-dom to V5 so that the code understands the  Statement. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Lets us take a look at both the solutions.&lt;/p&gt;
&lt;h2&gt;
  
  
  How to solve ‘Switch’ is not exported from ‘react-router-dom’ error in ReactJs? Solution 1
&lt;/h2&gt;

&lt;p&gt;In order to solve the ‘Switch’ is not exported from ‘react-router-dom’ error in ReactJs, we need to update the syntax of the routes defined. From version 6 onwards, the react-router-dom has replaced “Switch” with “Routes”. And hence we need to update the syntax accordingly. Let us take a look at the steps to solve the ‘Switch’ is not exported from ‘react-router-dom’ error.&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 1. Upgrade to React 16.8+ and react-router-dom v6+
&lt;/h3&gt;

&lt;p&gt;Firstly you would have to &lt;a href="https://www.moreonfew.com/how-to-install-specific-version-of-npm-package/"&gt;upgrade to react version 16.8&lt;/a&gt; or above version as react-router-dom version 6 makes heavy use of React hooks.&lt;/p&gt;

&lt;p&gt;Secondly, upgrade to react-router-dom v6+ using the following command if you are already not using the latest version or V6:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;npm&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;install&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;react-router-dom&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also &lt;a href="https://www.moreonfew.com/how-to-install-specific-version-of-npm-package/#How-to-install-the-latest-version-of-a-package-in-npm"&gt;use the @latest keyword to install the latest version of the package&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Update the react-router-dom import statement.
&lt;/h3&gt;

&lt;p&gt;Now that you have React 16.8+ and react-router-dom v6+, you should update the Router’s syntax. Firstly we need to &lt;strong&gt;update the import statement to import “Routes” instead of “Switch”.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So, Update the import statement like the following&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//import { Switch, Route } from "react-router-dom";&lt;/span&gt;
&lt;span class="c1"&gt;//to&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Routes&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;Route&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-router-dom&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 3: Upgrade the syntax and replace “Switch” with “Routes” and “component” with “element’
&lt;/h3&gt;

&lt;p&gt;The third step would be to replace the “Switch” with “Routes” and the “component” with “element” as shown in the example.&lt;/p&gt;

&lt;p&gt;So, &lt;strong&gt;replace the  with  and component attribute to element&lt;/strong&gt; , like in the following example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// &amp;lt;Switch&amp;gt;&lt;/span&gt;
&lt;span class="c1"&gt;// &amp;lt;Route path="/home" component={HomePage} /&amp;gt;&lt;/span&gt;
&lt;span class="c1"&gt;// &amp;lt;/Switch&amp;gt;&lt;/span&gt;

&lt;span class="c1"&gt;//to&lt;/span&gt;

&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Routes&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Route&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/home&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;HomePage&lt;/span&gt;&lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Routes&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Notice that the component={HomePage} too got updated to element={} as per the new syntax.&lt;/strong&gt; You can read more about the process to update react-router-dom from v5 to v6 at &lt;a href="https://reactrouter.com/docs/en/v6/upgrading/v5#upgrade-to-react-router-v6"&gt;https://reactrouter.com/docs/en/v6/upgrading/v5#upgrade-to-react-router-v6&lt;/a&gt; .&lt;/p&gt;

&lt;h2&gt;
  
  
  An alternative way to fix the ‘Switch’ is not exported from ‘react-router-dom’. Solution 2
&lt;/h2&gt;

&lt;p&gt;There is an alternative way to fix the ‘Switch’ is not exported from ‘react-router-dom’ error too. As we discussed earlier, the error is caused due to using react-router-dom version 6+ and using the older syntax of Router. So if you don’t have the time to update all the syntax, the alternative would be to downgrade the react-router-dom package to version 5.2.0 or 5.3.0.&lt;br&gt;&lt;br&gt;
You can downgrade to react-router-dom version 5.2.0 by first &lt;a href="https://www.moreonfew.com/how-to-remove-npm-package-from-a-project/"&gt;uninstalling the package&lt;/a&gt; version installed and then &lt;a href="https://www.moreonfew.com/how-to-install-specific-version-of-npm-package/"&gt;installing the v5.2.0&lt;/a&gt;. You can do so by using the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;npm&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;uninstall&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;react-router-dom&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;then use the following command to install a specific version of react-router-dom&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;npm&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;install&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;react-router-dom&lt;/span&gt;&lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="nx"&gt;5.2.0&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This way you would not have to worry about upgrading react-router-dom’s syntax and avoid all the hassle temporarily. On the long run I would recommend you to always upgrade to the latest version of the package . This can be useful to fix the issue ” ‘Routes’ is not exported from ‘react-router-dom’ “, which can be caused because you are using older version of react-router-dom but newer version of code.&lt;/p&gt;

&lt;p&gt;To conclude, I can say that to solve the ‘Switch’ is not exported from ‘react-router-dom’ error, the best way is to upgrade to react-router-dom v6 or above while updating the syntax too. However, alternatively, if you don’t want to update to react-router-dom version 6, you can also instead downgrade to version 5.2.0 , in which case, you need not update the syntax code too.&lt;/p&gt;

&lt;p&gt;This article first appeared on &lt;a href="https://www.moreonfew.com/attempted-import-error-switch-is-not-exported-from-react-router-dom/"&gt;https://www.moreonfew.com/attempted-import-error-switch-is-not-exported-from-react-router-dom/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>npm</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to remove a specific item from an array in JavaScript?</title>
      <dc:creator>MoreOnFew</dc:creator>
      <pubDate>Wed, 26 Jan 2022 08:14:38 +0000</pubDate>
      <link>https://dev.to/moreonfew/how-to-remove-a-specific-item-from-an-array-in-javascript-4dkb</link>
      <guid>https://dev.to/moreonfew/how-to-remove-a-specific-item-from-an-array-in-javascript-4dkb</guid>
      <description>&lt;p&gt;In JavaScript, the Array Object has been one of the most commonly used objects, and hence most of us would already have a good understanding of Array methods. However, there are times when we notice that there might not be a predefined method to achieve a certain task that might seem very common. One such case is the need to remove a specific item from an Array. Let us take a look at modern and simple way to remove a specific item from an Array in JavaScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to remove a specific item from Array by value in JavaScript
&lt;/h2&gt;

&lt;p&gt;As you might have already figured out, there are no predefined methods in the Array object that can help us remove a specific item from an Array &lt;strong&gt;by its value&lt;/strong&gt;. However, you can use the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter"&gt;Array Filter&lt;/a&gt; method to achieve it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example showing use of Array Filter method to remove specific item from Array
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;colors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;green&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;blue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;orange&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;pink&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;yellow&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;removeColor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;blue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;colors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;item&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="nx"&gt;removeColor&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="cm"&gt;/* ['red', 'green', 'orange', 'pink', 'yellow'] */&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can convert the above code into an Arrow function as shown in the next section.&lt;/p&gt;

&lt;h3&gt;
  
  
  Method to remove specific item from Array by value
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;removeByValue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;valueToRemove&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="nx"&gt;valueToRemove&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;colors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;green&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;blue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;orange&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;pink&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;yellow&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="nx"&gt;removeByValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;colors&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;blue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="cm"&gt;/* pass the array and the item value to be removed */&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output of the Above code would be as below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;green&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;orange&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;pink&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;yellow&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can notice, the returned value is a new Array after removing the item with value Blue. This way your original array stays intact.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to remove specific item from Array by Index in JavaScript
&lt;/h2&gt;

&lt;p&gt;On the other hand if you are looking to remove an item from Array &lt;strong&gt;using its index&lt;/strong&gt; , then you can try out the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;colors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;green&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;blue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;orange&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;pink&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;yellow&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;removeIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;colors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="nx"&gt;removeIndex&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="cm"&gt;/* ['red', 'green', 'orange', 'pink', 'yellow'] */&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above given code can also be written as an Arrow method as show below.&lt;/p&gt;

&lt;h3&gt;
  
  
  Method to remove specific item from Array by Index
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;removeByIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;indexToRemove&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="nx"&gt;indexToRemove&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;colors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;green&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;blue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;orange&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;pink&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;yellow&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="nx"&gt;removeByIndex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;colors&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="cm"&gt;/* pass the array and the Index of the item to be removed */&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output of the Above code would be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;green&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;orange&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;pink&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;yellow&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As I mentioned earlier, there are times when we might come across scenarios where there might not be an existing or predefined method available to be used for a very common task. In such cases the alternative we have is to use other predefined methods to create a custom method, which would help us achieve what we want. One such scenario is the need to remove a specific item from an Array. And as you can see, we can make use of the existing Array Filter method to achieve what we want.&lt;/p&gt;

&lt;p&gt;While there are many different ways available online to remove a specific item from an Array in JavaScript, including the splice() method, the ones shown above are modern and simple ways to do it. &lt;strong&gt;These methods would not alter the original Array and would keep it safe and immutable&lt;/strong&gt;. Hope you liked this article. You can also check our other &lt;a href="https://www.moreonfew.com/category/javascript/"&gt;JavaScript related tutorials and articles&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>tutorial</category>
      <category>programming</category>
    </item>
    <item>
      <title>How to get current url in JavaScript?</title>
      <dc:creator>MoreOnFew</dc:creator>
      <pubDate>Fri, 24 Sep 2021 12:06:45 +0000</pubDate>
      <link>https://dev.to/moreonfew/how-to-get-current-url-in-javascript-5f82</link>
      <guid>https://dev.to/moreonfew/how-to-get-current-url-in-javascript-5f82</guid>
      <description>&lt;p&gt;JavaScript has come a long way since its inception. I remember the days when it was mainly used only for form validations. Now we use JavaScript for a lot more functionalities. JavaScript has a vast number of APIs which enables us to access a variety of features and information from the browser. One such API is the window.location API which helps us to get current URL in javascript.&lt;/p&gt;

&lt;h2&gt;
  
  
  Get current URL in Javascript using windlow.location object
&lt;/h2&gt;

&lt;p&gt;Getting the current URL in JavaScript is quite simple using the &lt;a href="https://www.w3schools.com/js/js_window_location.asp"&gt;window.location&lt;/a&gt; object. You can &lt;strong&gt;get the current URL in javascript using the following code&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;window.location.href 
// https://www.moreonfew.com/how-to-get-current-url-in-javascript/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Using the JavaScript object window.location.href, you can get the current full URL of the page&lt;/strong&gt;. It would return you the URL of the current page with the protocol (“https”), the domain (“www.moreonfew.com”), and the path plus the filename (“how-to-get-current-url-in-javascript”). It would also return the query parameters in the URL if they are present. In this current page’s URL there aren’t any query parameters and hence we did not get it.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to get current URL in JQuery?
&lt;/h2&gt;

&lt;p&gt;If you are using jQuery and would like to get the current URL, then you can use the following code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$(location).attr('href');
// OR
$(location).prop('href');

// https://www.moreonfew.com/how-to-get-current-url-in-javascript/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you notice, in jQuery too, we need to access the “location” object in order to get the current URL. Once we access the location object, we use the “attr” or “prop” API to get the “href” attribute’s value.&lt;/p&gt;

&lt;p&gt;However, I would suggest that &lt;strong&gt;it’s better to use window.location.href as it would be comparatively faster and simpler too&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I hope that you enjoyed reading about the method to get current URL in JavaScript. As you noticed, the way to get current URL in jQuery is also very similar and the “location” object is what we need to tap into even in the case of jQuery. If you liked this article, you can find more &lt;a href="https://www.moreonfew.com/category/web/javascript/"&gt;JavaScript articles under our JavaScript section&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://www.moreonfew.com/how-to-get-current-url-in-javascript/"&gt;How to get current url in JavaScript?&lt;/a&gt; first appeared on &lt;a href="https://www.moreonfew.com"&gt;MoreOnFew&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>How to install specific version of npm package?</title>
      <dc:creator>MoreOnFew</dc:creator>
      <pubDate>Thu, 23 Sep 2021 17:31:38 +0000</pubDate>
      <link>https://dev.to/moreonfew/how-to-install-specific-version-of-npm-package-2n5a</link>
      <guid>https://dev.to/moreonfew/how-to-install-specific-version-of-npm-package-2n5a</guid>
      <description>&lt;p&gt;As you might already know, there are a large number of npm packages released every day. An equally large number of updates too get released on the npm registry. While we would like to keep the dependencies in package.json updated to the latest version most of the times, there are still times when we would like to install specific version of npm package for certain reasons.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to install an exact or specific version of npm package?
&lt;/h2&gt;

&lt;p&gt;In order to &lt;a href="https://www.moreonfew.com/how-to-install-specific-version-of-npm-package/"&gt;install a specific version of npm package&lt;/a&gt; &lt;strong&gt;run the npm install command along with the package name followed by the version number prefixed with the at symbol “@”&lt;/strong&gt;. Here is the syntax for the same:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;npm&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;install&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;package_name&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;@&lt;/span&gt;&lt;span class="nx"&gt;version_number&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For example, let’s say I wanted to install React version 17.0.2, then the command would be :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;npm&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;install&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;react&lt;/span&gt;&lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="nx"&gt;17.0.2&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you notice, the command is very similar to the basic command to install a package, however, the only difference is the @version_number that follows the package name as a suffix.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to install the latest version of a package in npm?
&lt;/h2&gt;

&lt;p&gt;On the other hand, if you would like &lt;strong&gt;to install the latest version of an npm package&lt;/strong&gt; , use the same command but instead of specifying the version number, &lt;strong&gt;use the “latest” keyword&lt;/strong&gt; like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;npm&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;install&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;package_name&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;@&lt;/span&gt;&lt;span class="nx"&gt;latest&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For example, to install the latest version of React, the command would be&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;npm&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;install&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;react&lt;/span&gt;&lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="nx"&gt;latest&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Please note that both these commands can be used along with the &lt;code&gt;--save&lt;/code&gt; and &lt;code&gt;--save-dev&lt;/code&gt; etc flags too whenever required.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As you can see, it is quite simple to install specific version of npm package or to install the latest version of a package too. You can also &lt;a href="https://www.moreonfew.com/how-to-find-outdated-packages-in-npm/"&gt;find outdated packages&lt;/a&gt; or &lt;a href="https://www.moreonfew.com/how-to-find-unused-dependencies-in-npm/"&gt;unused dependencies in npm&lt;/a&gt; and &lt;a href="https://www.moreonfew.com/how-to-remove-npm-package-from-a-project/"&gt;remove those npm packages&lt;/a&gt; too in order to keep your project optimized. Hope you found this article helpful.&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://www.moreonfew.com/how-to-install-specific-version-of-npm-package/"&gt;How to install specific version of npm package?&lt;/a&gt; first appeared on &lt;a href="https://www.moreonfew.com"&gt;MoreOnFew&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>node</category>
      <category>npm</category>
    </item>
    <item>
      <title>Know the difference between tilde and caret in package.json</title>
      <dc:creator>MoreOnFew</dc:creator>
      <pubDate>Fri, 17 Sep 2021 19:46:48 +0000</pubDate>
      <link>https://dev.to/moreonfew/know-the-difference-between-tilde-and-caret-in-packagejson-37hd</link>
      <guid>https://dev.to/moreonfew/know-the-difference-between-tilde-and-caret-in-packagejson-37hd</guid>
      <description>&lt;p&gt;Most of us might have wondered what does the &lt;strong&gt;tilde (~)&lt;/strong&gt; and &lt;strong&gt;caret (^)&lt;/strong&gt; prefixing the version number of the “dependencies” in your package.json file mean. Well, it is important to know the difference between tilde and caret in package.json as the wrong usage can even break your project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding the usage of tilde (~) and caret(^) in package.json
&lt;/h2&gt;

&lt;p&gt;The tilde (~) and caret(^) have a very specific use in the package.json file and they both convey different messages. To understand it better, let’s take a look at an example of dependencies in the package.json file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"dependencies": {
  "next": "^11.0.0",

  "react": "~17.0.2",
  "react-dom": "~17.0.2"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above, we can notice that the “next” package has a caret (^) prefixing its version number, while on the other hand, the other two packages have a tilde(~) prefixing its version number.&lt;/p&gt;

&lt;p&gt;We can also notice that the version numbers usually have 3 integers(can be alphanumeric too) which are separated by a dot in between two integers. They are in the format of &lt;strong&gt;Major.Minor.Patch&lt;/strong&gt;.For e.g 17.0.2 , which means that the Major version is 17, Minor version is 0, and the Patch version is 2.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi2.wp.com%2Fwww.moreonfew.com%2Fwp-content%2Fuploads%2F2021%2F09%2Fpackage-version-numbering-3.png%3Fresize%3D950%252C768%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi2.wp.com%2Fwww.moreonfew.com%2Fwp-content%2Fuploads%2F2021%2F09%2Fpackage-version-numbering-3.png%3Fresize%3D950%252C768%26ssl%3D1" alt="Example of package version numbering"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;NPM Package version numbers are in the format of Major.Minor.Patch&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;Patch version&lt;/strong&gt; usually refers to very minor updates like a security patch, bug fix, etc. Usually upgrading from one patch to another is not harmful. For e.g upgrading from 17.0. &lt;strong&gt;2&lt;/strong&gt; to 17.0. &lt;strong&gt;3&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;Minor version&lt;/strong&gt; upgrade usually refers to the introduction of new features and /or upgrades and are not just patch fixes or security fixes. The upgraded version will still be backward compatible and will not break your functionality. For e.g upgrading from 17. &lt;strong&gt;0&lt;/strong&gt;.2 to 17. &lt;strong&gt;1&lt;/strong&gt;.0&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;Major version&lt;/strong&gt; upgrade would mean that a major refactoring of the code has been done and there might be breaking changes that have been introduced. For e.g upgrading from &lt;strong&gt;17&lt;/strong&gt;.0.2 to &lt;strong&gt;18&lt;/strong&gt;.0.0&lt;/p&gt;

&lt;p&gt;You can read more about the semantic version numbering at &lt;a href="https://semver.org/" rel="noopener noreferrer"&gt;https://semver.org/&lt;/a&gt; and at &lt;a href="https://docs.npmjs.com/about-semantic-versioning#incrementing-semantic-versions-in-published-packages" rel="noopener noreferrer"&gt;NPM Docs&lt;/a&gt;. Well, now that we understand the version’s numbering, let’s take a look at what does tilde (~) and caret (^) symbols signify.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is tilde in package json?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;A tilde (~) as a prefix to the version number in package JSON means&lt;/strong&gt; that whenever an update is run or whenever the packages are installed, it would &lt;strong&gt;look for the latest patch version available in the npm registry&lt;/strong&gt; and install it. In other words, if say the version was mentioned as “~17.0. &lt;strong&gt;2&lt;/strong&gt; “, it can go ahead and upgrade to 17.0. &lt;strong&gt;x&lt;/strong&gt; version where x is the highest available patch version in that Major.Minor.Patch combination. This means that the max it can go until is “17.0. &lt;strong&gt;9&lt;/strong&gt; ” (if 9 was the last patch released). &lt;strong&gt;A tilde basically asks the npm to install only the latest patch version of the package and ignore any minor or major upgrades&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi1.wp.com%2Fwww.moreonfew.com%2Fwp-content%2Fuploads%2F2021%2F09%2Ftilde-prefix-packagejson.png%3Fresize%3D924%252C696%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi1.wp.com%2Fwww.moreonfew.com%2Fwp-content%2Fuploads%2F2021%2F09%2Ftilde-prefix-packagejson.png%3Fresize%3D924%252C696%26ssl%3D1" alt="Example of Tilde Prefix in package.json"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;With Tilde ( ~ ) as the prefix, npm would update the package to the latest patch version available.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  What is Caret in package.json?
&lt;/h3&gt;

&lt;p&gt;On the other hand, A &lt;strong&gt;Caret (^) as a prefix to the version number in package.json means&lt;/strong&gt; that whenever an update is run or the packages are installed, &lt;strong&gt;look for the latest minor and its latest patch version&lt;/strong&gt; available in the npm registry and install it. This means that if the version in package.json was mentioned as “^17. &lt;strong&gt;0&lt;/strong&gt;. &lt;strong&gt;2&lt;/strong&gt; “, it can update until version “17. &lt;strong&gt;x&lt;/strong&gt;. &lt;strong&gt;x&lt;/strong&gt; “, where x is the highest minor and patch version available. So assume if react has released a version 17.1.1 recently and I run the npm update command, npm would go ahead and &lt;strong&gt;upgrade the package from version “17.0.2” to “17.1.1”&lt;/strong&gt;. &lt;strong&gt;Now assume if React released version 18.0.1&lt;/strong&gt; and I run the update, &lt;strong&gt;even then I would still get only version 17.1.1&lt;/strong&gt; (if that was the latest version before releasing version 18.0.1)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi1.wp.com%2Fwww.moreonfew.com%2Fwp-content%2Fuploads%2F2021%2F09%2Fcaret-prefix-packagejson2x-1.png%3Fresize%3D934%252C768%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi1.wp.com%2Fwww.moreonfew.com%2Fwp-content%2Fuploads%2F2021%2F09%2Fcaret-prefix-packagejson2x-1.png%3Fresize%3D934%252C768%26ssl%3D1" alt="Example of Caret Prefix in package.json"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;With Caret (^) as prefix, npm would update the package to the latest minor and its latest patch version.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Please note that with Caret as prefix, even though it updates to the latest minor and its latest patch version , the Major version number remains the same.&lt;/strong&gt; Most of the times the package would be backwards compatible too.&lt;/p&gt;

&lt;h3&gt;
  
  
  The core difference between tilde and caret in package.json
&lt;/h3&gt;

&lt;p&gt;Well, to summarize, we can say that the core difference between tilde and caret in package.json is mainly to do with instructing the npm on which latest version of the package should be installed. &lt;strong&gt;A tilde ( ~ ) would mean that the latest Patch version of a specific Major.Minor combination should be installed&lt;/strong&gt; e.g 17.0. &lt;strong&gt;2&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A caret ( ^ ) would mean that the latest Minor and its latest patch version should be installed&lt;/strong&gt; e.g 17. &lt;strong&gt;9&lt;/strong&gt;. &lt;strong&gt;9&lt;/strong&gt;. In both cases, the Major version remains the same e.g &lt;strong&gt;17&lt;/strong&gt;.0.2 and &lt;strong&gt;17&lt;/strong&gt;.9.9 both have 17 as the Major version number.&lt;/p&gt;

&lt;p&gt;If you want to &lt;a href="https://www.moreonfew.com/how-to-install-specific-version-of-npm-package/" rel="noopener noreferrer"&gt;install a specific version of npm package&lt;/a&gt;, you can do that too by removing both the tilde and caret signs and by just keeping the exact package version number like “react” : “17.0.2”&lt;/p&gt;

&lt;h4&gt;
  
  
  Tool to check the semantic version number Range in package.json
&lt;/h4&gt;

&lt;p&gt;You can also use Semantic version calculator from official NPMJs website at &lt;a href="https://semver.npmjs.com/" rel="noopener noreferrer"&gt;https://semver.npmjs.com/&lt;/a&gt; . Here you can try out the tilde and caret prefixes to check which versions of package would be covered with it. You can even select the package of your choice and try out the prefix.&lt;/p&gt;

&lt;p&gt;I hope you are clear with the difference between tilde and caret in package.json. As I mentioned earlier, it is important that we understand the difference between tilde and Caret in package.json. Wrong usage of the tilde or caret can cause breakages in your app. If for some reason you installed the wrong version of package, you can go ahead and &lt;a href="https://www.moreonfew.com/how-to-remove-npm-package-from-a-project/" rel="noopener noreferrer"&gt;remove the npm package from project&lt;/a&gt; and install the desired version.&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://www.moreonfew.com/difference-between-tilde-and-caret-in-package-json/" rel="noopener noreferrer"&gt;Know the difference between tilde and caret in package.json&lt;/a&gt; first appeared on &lt;a href="https://www.moreonfew.com" rel="noopener noreferrer"&gt;MoreOnFew&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>npm</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How to remove npm package from a project?</title>
      <dc:creator>MoreOnFew</dc:creator>
      <pubDate>Mon, 13 Sep 2021 17:59:21 +0000</pubDate>
      <link>https://dev.to/moreonfew/how-to-remove-npm-package-from-a-project-1bk8</link>
      <guid>https://dev.to/moreonfew/how-to-remove-npm-package-from-a-project-1bk8</guid>
      <description>&lt;p&gt;NPM or Node Package Manager has made it really easy to install and manage packages in JavaScript projects. The number of packages available on npm has been on an increase and it has become very convenient to install a package in a project using npm. However, over time, it becomes important to remove npm package from the project which might be &lt;a href="https://www.moreonfew.com/how-to-find-outdated-packages-in-npm/"&gt;outdated&lt;/a&gt; on &lt;a href="https://www.moreonfew.com/how-to-find-unused-dependencies-in-npm/"&gt;unused&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Remove npm package from package.json
&lt;/h2&gt;

&lt;p&gt;Removing an npm package from package.json is quite easy and straightforward. You can &lt;strong&gt;run the following command to remove or uninstall a package&lt;/strong&gt; :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm uninstall &amp;lt;package_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For example, let us say we want &lt;strong&gt;to remove the bootstrap package&lt;/strong&gt; from the project. The command would be :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm uninstall bootstrap
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;If you installed a package as a devDependency using the &lt;code&gt;--save-dev&lt;/code&gt; command, you need to use the &lt;code&gt;--save-dev&lt;/code&gt; along with the uninstall command&lt;/strong&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;npm uninstall --save-dev bootstrap
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How to uninstall global npm package?
&lt;/h2&gt;

&lt;p&gt;Uninstalling global npm package is also very similar. &lt;strong&gt;To uninstall global npm package you need to run the following command&lt;/strong&gt; :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm uninstall -g &amp;lt;package_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For example, if you want to uninstall jsHint which say was installed globally, you can run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm uninstall -g jshint
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Once you run the uninstall command,&lt;/strong&gt; you can notice that &lt;strong&gt;the folder related to the package that you uninstalled would be deleted from the node_modules folder&lt;/strong&gt; too, and &lt;strong&gt;also the reference of the package in the package.json file would be removed&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I hope you have learned how to remove npm package from a project. It is important that we regularly find and remove &lt;a href="https://www.moreonfew.com/how-to-find-outdated-packages-in-npm/"&gt;outdated packages&lt;/a&gt; and &lt;a href="https://www.moreonfew.com/how-to-find-unused-dependencies-in-npm/"&gt;unused packages&lt;/a&gt; from package.json. You can find the outdated and unused packages and use the command to remove these packages to keep your package dependencies in control and to avoid bloating up the build files. Hope you found the article to be helpful. Let us know in the comments.&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://www.moreonfew.com/how-to-remove-npm-package-from-a-project/"&gt;How to remove npm package from a project?&lt;/a&gt; first appeared on &lt;a href="https://www.moreonfew.com"&gt;MoreOnFew&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>node</category>
      <category>npm</category>
    </item>
    <item>
      <title>How to find outdated packages in npm?</title>
      <dc:creator>MoreOnFew</dc:creator>
      <pubDate>Mon, 13 Sep 2021 12:51:26 +0000</pubDate>
      <link>https://dev.to/moreonfew/how-to-find-outdated-packages-in-npm-511n</link>
      <guid>https://dev.to/moreonfew/how-to-find-outdated-packages-in-npm-511n</guid>
      <description>&lt;p&gt;NPM as a package manager has been a very useful tool in web development. Using npm has made it very convenient for us to add various packages to our web development projects. However, like with other software, our npm packages too get outdated either because a new feature has been introduced, the code has been optimized, or because some security fixes have been released. Nonetheless, it becomes important to find outdated packages in npm and to either &lt;a href="https://www.moreonfew.com/how-to-remove-npm-package-from-a-project/"&gt;remove&lt;/a&gt; them or update them like we would &lt;a href="https://www.moreonfew.com/how-to-find-unused-dependencies-in-npm/"&gt;find unused dependencies in npm&lt;/a&gt; and remove them too to keep our build optimized.&lt;/p&gt;

&lt;h2&gt;
  
  
  How do I check for outdated npm packages?
&lt;/h2&gt;

&lt;p&gt;Checking for outdated packages in npm is not a difficult task. You can &lt;strong&gt;run the following command to find outdated packages in npm&lt;/strong&gt; :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm outdated
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above command is inbuilt and you do not have to install any additional packages for it. Running the &lt;strong&gt;npm outdated command would list out all the outdated packages along with their latest version number&lt;/strong&gt;. Following is an example of the command I ran on a trial app that I have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;D:\Project&amp;gt;npm outdated
Package Current Wanted Latest Location
bootstrap 5.0.0 5.0.1 5.1.1 MyApp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When we run the &lt;code&gt;npm outdated&lt;/code&gt; command, we get to see the name of the package that is outdated with few other data which are as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Package&lt;/strong&gt; : This is the name of the package that is outdated&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Current&lt;/strong&gt; : This is the version number of the package that is currently installed, i.e the outdated package&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Wanted&lt;/strong&gt; : This is the highest version of the package that satisfies the &lt;a href="https://semver.org/"&gt;semver&lt;/a&gt; range defined in the package.json file. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Latest&lt;/strong&gt; : This is the latest version number of the package that is available to download.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Location&lt;/strong&gt; : This is the name of the app as defined in the package.json.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  What is the difference between Wanted vs Latest in npm outdated command?
&lt;/h3&gt;

&lt;p&gt;Well, one can easily get confused between the wanted vs latest when running the npm outdated command.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Wanted version basically is the highest version of the package that can be fetched as per your package.json declaration. Whereas, the Latest version is the latest or the newest version of the package available on npm’s registry for download&lt;/strong&gt;. For example. let’s say that I’ve bootstrap’s version 5.0.0 installed on my machine. But in my package.json file, I have declared to install the exact version number 5.0.1, like the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"dependencies": {
  "bootstrap": "5.0.1"

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In such a case when I run npm outdated command, the wanted version would be 5.0.1, because I’ve explicitly declared in my package.json that I want version 5.0.1 of bootstrap to be installed and nothing else. However, the latest version would still be 5.1.1, because as per the npm registry information, the latest version available is 5.1.1 (at the time I wrote this). In other words, the Wanted version is bound by the declaration in package.json. It can only go until the range that is permitted as per the package.json declaration either by giving the exact version or by using ~ (tilde) or ^ (caret) sign before the version number.&lt;/p&gt;

&lt;p&gt;Hope the Wanted vs Latest in npm outdated command is clear now. Let us know in the comments if you have any doubts.&lt;/p&gt;

&lt;h3&gt;
  
  
  What does the Color codes mean in NPM Outdated command?
&lt;/h3&gt;

&lt;p&gt;You might also notice while running the command that the package name might be in red or yellow.&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;red color indicates&lt;/strong&gt; that there is a &lt;strong&gt;newer version matching your semver&lt;/strong&gt; requirement and you should update now.&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;yellow color indicates&lt;/strong&gt; that there is a &lt;strong&gt;newer version above your semver range r&lt;/strong&gt; equirements and hence you need to &lt;strong&gt;be careful while updating&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Well, I believe it was an easy task to find outdated packages in npm using the simple &lt;code&gt;npm outdated&lt;/code&gt; command. It is very important that we find outdated packages and update outdated npm packages so that we don’t run into security issues or other errors. Equally important is to &lt;a href="https://www.moreonfew.com/how-to-find-unused-dependencies-in-npm/"&gt;find unused dependencies in npm&lt;/a&gt; and to &lt;a href="https://www.moreonfew.com/how-to-remove-npm-package-from-a-project/"&gt;remove these unused dependencies&lt;/a&gt; to keep your build sizes optimized.&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://www.moreonfew.com/how-to-find-outdated-packages-in-npm/"&gt;How to find outdated packages in npm?&lt;/a&gt; first appeared on &lt;a href="https://www.moreonfew.com"&gt;MoreOnFew&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>node</category>
      <category>npm</category>
    </item>
    <item>
      <title>How to find unused dependencies in npm?</title>
      <dc:creator>MoreOnFew</dc:creator>
      <pubDate>Mon, 13 Sep 2021 07:19:11 +0000</pubDate>
      <link>https://dev.to/moreonfew/how-to-find-unused-dependencies-in-npm-4f0a</link>
      <guid>https://dev.to/moreonfew/how-to-find-unused-dependencies-in-npm-4f0a</guid>
      <description>&lt;p&gt;NPM has become the most popular package manager over time. It is really helpful and useful to manage the package dependencies of your project. However, over time, as your project keeps growing and new packages get released, there are times when we move on to a better alternative of a package or even stop using a package since we might not require it anymore. In such cases, it is important that we find unused dependencies in our npm’s package.json so that our project does not get bloated up. It also is important to &lt;a href="https://www.moreonfew.com/how-to-find-outdated-packages-in-npm/"&gt;find outdated packages in npm&lt;/a&gt; and to update or &lt;a href="https://www.moreonfew.com/how-to-remove-npm-package-from-a-project/"&gt;remove&lt;/a&gt; them.&lt;/p&gt;

&lt;p&gt;Finding unused packages manually can be a very cumbersome process and might not be efficient too. In such cases, it is recommended to use any tool that would help you find unused dependencies in package.json.&lt;/p&gt;

&lt;h2&gt;
  
  
  Here is how you can find unused dependencies in package.json via npm
&lt;/h2&gt;

&lt;p&gt;As I mentioned earlier, finding unused dependencies in package.json manually can be a really tedious task. The easier alternative is to use a tool that would make your task fast and easy. One such tool is &lt;a href="https://www.npmjs.com/package/depcheck"&gt;depcheck&lt;/a&gt;. In their own words :&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Depcheck is a tool for analyzing the dependencies in a project to see: how each dependency is used, which dependencies are useless, and which dependencies are missing from package.json&lt;/p&gt;

&lt;p&gt;&lt;cite&gt;&lt;a href="https://www.npmjs.com/package/depcheck"&gt;https://www.npmjs.com/package/depcheck&lt;/a&gt;&lt;/cite&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The usage of it is fairly simple. &lt;strong&gt;Run the following command and it would find all the unused dependencies in your package.json&lt;/strong&gt; :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx depcheck
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The command above would execute the package without installing it on your machine. If you are looking &lt;strong&gt;to install the package and run it&lt;/strong&gt; then you can &lt;strong&gt;try the following command&lt;/strong&gt; :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npm install -g depcheck

$ depcheck
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Below is an example of running depcheck on a sample project where I’ve installed bootstrap but haven’t used it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;D:\project&amp;gt;npx depcheck
npx: installed 146 in 20.628s
Unused dependencies
* bootstrap
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, you can notice that after running the npx depcheck command, it runs the tool and lists the unused dependencies which in my case was only bootstrap. If there were more, it would list all the unused packages in package.json.&lt;/p&gt;

&lt;p&gt;Please note that you need to &lt;strong&gt;run the commands in the directory where the package.json file can be found&lt;/strong&gt; since by default it looks for the package.json file in the root directory. Also, please note that &lt;strong&gt;you need to have nodejs version 10 or greater installed&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;There are many more options that depcheck provides and you can check them out on their official page at &lt;a href="https://www.npmjs.com/package/depcheck"&gt;https://www.npmjs.com/package/depcheck&lt;/a&gt; .&lt;/p&gt;

&lt;p&gt;To conclude I would say that it is very easy to find unused dependencies in package.json using npm packages like depcheck etc. It is a good practice to keep the package dependencies on the check and to regularly &lt;a href="https://www.moreonfew.com/how-to-remove-npm-package-from-a-project/"&gt;remove all the unused package dependencies&lt;/a&gt;. It is equally important to &lt;a href="https://www.moreonfew.com/how-to-find-outdated-packages-in-npm/"&gt;find outdated packages in npm&lt;/a&gt; and to either update them or &lt;a href="https://www.moreonfew.com/how-to-remove-npm-package-from-a-project/"&gt;remove those outdated packages&lt;/a&gt;. Hope you found this article to be useful.&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://www.moreonfew.com/how-to-find-unused-dependencies-in-npm/"&gt;How to find unused dependencies in npm?&lt;/a&gt; first appeared on &lt;a href="https://www.moreonfew.com"&gt;MoreOnFew&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>node</category>
      <category>npm</category>
    </item>
    <item>
      <title>Uncaught SyntaxError: Unexpected end of input – Causes And Fix!</title>
      <dc:creator>MoreOnFew</dc:creator>
      <pubDate>Mon, 06 Sep 2021 12:14:47 +0000</pubDate>
      <link>https://dev.to/moreonfew/uncaught-syntaxerror-unexpected-end-of-input-causes-and-fix-100j</link>
      <guid>https://dev.to/moreonfew/uncaught-syntaxerror-unexpected-end-of-input-causes-and-fix-100j</guid>
      <description>&lt;p&gt;I know that sometimes the errors we face in JavaScript can be difficult to debug. While with all the modern tools like Chrome developer tools etc the debugging has become far easier, there still are times when we come across issues that are tricky to debug. One such issue is the “ &lt;strong&gt;Uncaught SyntaxError: Unexpected end of input&lt;/strong&gt; ” error in JavaScript.&lt;/p&gt;

&lt;p&gt;Let us take a look at how can we debug such issues and what might be causing them.&lt;/p&gt;

&lt;h2&gt;
  
  
  What causes Unexpected end of Input in JavaScript?
&lt;/h2&gt;

&lt;p&gt;Well, a large number of times, the cause of the “Uncaught SyntaxError: Unexpected end of input” error in JavaScript is &lt;strong&gt;missing parentheses, brackets, or quotes&lt;/strong&gt;. Let’s take a look at the example below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var addPost = function() {
   //add a new post when called
}

var editPost = function() {
   //edit the post when called
}

var deletePost = function() {
   //delete a post when called

var publishPost = function() {
   //publish a post when called
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While everything looks good in the code above, this was throwing the Unexpected end of input error. However, if you look carefully, you’ll notice that the &lt;code&gt;deletePost&lt;/code&gt; method has a missing closing bracket ( &lt;strong&gt;}&lt;/strong&gt; ) which is actually causing the error.&lt;/p&gt;

&lt;p&gt;On a javascript file with hundreds of lines of code, it can become very cumbersome to track the brackets line by line. There is an easier way to catch such errors and to avoid them too as shown in the next section.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to fix Uncaught SyntaxError: Unexpected end of input error in JavaScript or jQuery?
&lt;/h2&gt;

&lt;p&gt;Now that we know what causes this issue, the debugging method is also easy. While we can definitely look into the code and brackets and parentheses line by line, it would not be an effective method in the case of a large file. The easier way would be to make use of any tool.&lt;/p&gt;

&lt;p&gt;One such tool I would recommend is &lt;a href="https://jshint.com/"&gt;https://jshint.com/&lt;/a&gt; .&lt;/p&gt;

&lt;p&gt;Once you visit JsHint, copy and paste your javascript code there. It would run an auto-scan of the code and list all the warnings and errors that the tool finds.&lt;/p&gt;

&lt;p&gt;If you copy-paste the above code on JSHint, you’ll notice that it shows an ” &lt;strong&gt;Unmatched ‘{‘.&lt;/strong&gt; ” warning. Once you hover over it, it would highlight the line with the deletePost method indicating that the missing bracket is in this method. Here is a screenshot that shows the issue on JsHint.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CDgvUWj0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i0.wp.com/www.moreonfew.com/wp-content/uploads/2021/09/jsHintScreenshot.png%3Fresize%3D1024%252C369%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CDgvUWj0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i0.wp.com/www.moreonfew.com/wp-content/uploads/2021/09/jsHintScreenshot.png%3Fresize%3D1024%252C369%26ssl%3D1" alt="Screenshot showing the unmatched bracket warning in JsHint tool" width="880" height="317"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Screenshot showing the unmatched bracket warning in JsHint tool&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Can the error be caused due to any other reason other than missing brackets etc?
&lt;/h2&gt;

&lt;p&gt;Yes! While it is true that most of the time the issue is caused due to missing parentheses, brackets, or quotes, it has been noticed that &lt;strong&gt;whenever we try to parse an empty response from a JSON&lt;/strong&gt; returned by Ajax call, the Unexpected end of input error can crop up too.&lt;/p&gt;

&lt;p&gt;In such cases, add a conditional check to see if the data returned really has something within it before making use of the data returned.&lt;/p&gt;

&lt;p&gt;For example, consider the following Ajax call in jQuery:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$.ajax({
   url: url,
   ...
   success: function (response) {

      if(response.data.length == 0){
         // this condition would prevent a blank json from being parsed
         // Empty response returned, maybe show an error etc
      }else{
        //Parse the JSON and use it
      }
   }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code, you can notice that once we receive the response, we check if the length of the data returned is 0 i.e if the data returned is empty then maybe write a handler method or show an error to the user, otherwise, if there is data then parse it and use it. Without this condition, the code would have thrown the unexpected end of input error.&lt;/p&gt;

&lt;p&gt;As I mentioned earlier, the “ &lt;strong&gt;Uncaught SyntaxError: Unexpected end of input” error in JavaScript&lt;/strong&gt; can be caused due to various reasons, however, the majority of the time it is &lt;strong&gt;because of missing parentheses, bracket, quote or because of parsing an empty JSON&lt;/strong&gt;. However, an easy way to spot and avoid such issues is to run your javaScript through a validator like jsHint.com. If you are using webpack then you can even configure JSLinting in your build process which would highlight such warnings and errors during the build time itself. Hope you would this article useful. Let us know in the comments!&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://www.moreonfew.com/uncaught-syntaxerror-unexpected-end-of-input-resolved/"&gt;Uncaught SyntaxError: Unexpected end of input – Causes And Fix!&lt;/a&gt; first appeared on &lt;a href="https://www.moreonfew.com"&gt;MoreOnFew&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>tooling</category>
      <category>programming</category>
    </item>
    <item>
      <title>What is the difference between Number.isInteger() and Number.isSafeInteger() in JavaScript ?</title>
      <dc:creator>MoreOnFew</dc:creator>
      <pubDate>Wed, 12 Sep 2018 09:18:32 +0000</pubDate>
      <link>https://dev.to/moreonfew/what-is-the-difference-between-numberisinteger-and-numberissafeinteger-in-javascript--18c7</link>
      <guid>https://dev.to/moreonfew/what-is-the-difference-between-numberisinteger-and-numberissafeinteger-in-javascript--18c7</guid>
      <description>&lt;p&gt;As a part of ES6 (also known as ECMAScript 2015 or ECMAScript 6), there are a couple of new JavaScript features and methods introduced. Today we would be concentrating on just two of them i.e &lt;code&gt;Number.isInteger()&lt;/code&gt; and &lt;code&gt;Number.isSafeInteger()&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is &lt;code&gt;Number.isInteger()&lt;/code&gt; ?
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;Number.isInteger()&lt;/code&gt; is a new method of the Number object introduced as a part of ES6. This is an interesting and useful feature that can help you save some time with mathematical operations. The &lt;code&gt;Number.isInteger()&lt;/code&gt; method basically tells you if the number passed on to the method as a parameter or argument is an Integer or not. So say if I pass a number that is Integer to the method it would return a boolean true. However, if I pass anything else to it, it would return false. Let’s take a look at an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isInteger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//returns true&lt;/span&gt;

&lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isInteger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;13.5&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//returns false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Please note that the &lt;code&gt;Number.isInteger()&lt;/code&gt; method returns a Boolean value always.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Number.isInteger()&lt;/code&gt; should not be confused with the &lt;code&gt;parseInt()&lt;/code&gt; method. The &lt;code&gt;parseInt()&lt;/code&gt; method parses the parameter string to a number (assuming the data type of the parameter ‘number’ was string and you want JavaScript to understand it as an Integer), and return the value as an integer. If it cannot parse it as a number, it returns NaN (Not a Number). &lt;code&gt;Number.isInteger()&lt;/code&gt; on the other hand checks if the parameter number passed to it is an integer already and returns true or false accordingly.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is &lt;code&gt;Number.isSafeInteger()&lt;/code&gt; ?
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;Number.isSafeInteger()&lt;/code&gt; on the other hand, is a method that is very similar to the &lt;code&gt;Number.isInteger()&lt;/code&gt;, however, it checks if the value is a “Safe Integer”, Safe integers are all integers from -(2&lt;sup&gt;53&lt;/sup&gt; – 1) to +(2&lt;sup&gt;53&lt;/sup&gt; – 1) i.e -9007199254740991 to 9007199254740991. Let’s take a look at an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isSafeInteger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns true&lt;/span&gt;

&lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isSafeInteger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;12345678901234567890&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns false&lt;/span&gt;

&lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isSafeInteger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;9007199254740991&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns true&lt;/span&gt;

&lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isSafeInteger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;9007199254740992&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Please note that &lt;code&gt;Number.isSafeInteger()&lt;/code&gt; too returns a Boolean value (true or false) always.&lt;/p&gt;

&lt;p&gt;You can find out the range of Safe Integer using two new properties of the number object which are &lt;code&gt;Number.MIN_SAFE_INTEGER&lt;/code&gt; (returns -9007199254740991) and &lt;code&gt;Number.MAX_SAFE_INTEGER&lt;/code&gt; (returns 9007199254740991) .&lt;/p&gt;

&lt;h2&gt;
  
  
  But, What is a Safe Integer anyway?
&lt;/h2&gt;

&lt;p&gt;“Safe Integer” is not a mathematical term and hence if you ask your Mathematics Genius friend about it he/she might not be aware of it at all. The “Safe Integer” here talks about Integers that are safe and stable to be used in JavaScript. JavaScript numbers have only enough storage space to represent integers in the range of -(2&lt;sup&gt;53&lt;/sup&gt; – 1) to +(2&lt;sup&gt;53&lt;/sup&gt; – 1), beyond this point the JavaScript integers are unsafe or unstable. Beyond 2&lt;sup&gt;53&lt;/sup&gt; , JavaScript can represent only every second mathematical integer. For example :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;53&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="c1"&gt;//9007199254740992&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;9007199254740992&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//9007199254740992&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;9007199254740993&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// 9007199254740992 Surprising!!&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;9007199254740994&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//9007199254740994 fine !&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;9007199254740995&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// 9007199254740996&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hence you require &lt;code&gt;Number.isSafeInteger()&lt;/code&gt; to find out if the integer is safe or not in JavaScript’s context.&lt;/p&gt;

&lt;p&gt;There are other new Math and Number related properties and Methods that ES6 has introduced and I would recommend that you try those out too along with the &lt;code&gt;Number.isInteger()&lt;/code&gt;; and the &lt;code&gt;Number.isSafeInteger()&lt;/code&gt; methods. Do let us know if you learned anything new today.&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://www.moreonfew.com/difference-between-number-isinteger-and-number-issafeinteger-in-javascript/"&gt;What is the difference between Number.isInteger() and Number.isSafeInteger() in JavaScript ?&lt;/a&gt; first appeared on &lt;a href="https://www.moreonfew.com"&gt;MoreOnFew&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How to detect support for a CSS feature using @supports ?</title>
      <dc:creator>MoreOnFew</dc:creator>
      <pubDate>Mon, 10 Sep 2018 12:32:23 +0000</pubDate>
      <link>https://dev.to/moreonfew/how-to-detect-support-for-a-css-feature-using-supports--5cmc</link>
      <guid>https://dev.to/moreonfew/how-to-detect-support-for-a-css-feature-using-supports--5cmc</guid>
      <description>&lt;p&gt;With many new CSS features being introduced regularly it has become important to check for the support of these newer CSS properties before we use them. While there are feature detection tools like Modernizr etc, not every time do we actually require to load a JavaScript file to detect a feature alone. You can do feature detection using CSS &lt;code&gt;@supports&lt;/code&gt; rule too. However, please note that the older versions of Browsers do not support &lt;code&gt;@supports&lt;/code&gt; rule too. In such a case I would suggest that you write small snippets of code in JavaScript to detect the support for the feature you are looking for.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to use the &lt;code&gt;@supports&lt;/code&gt; CSS rule ?
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;@supports&lt;/code&gt; CSS rule is one among other CSS at-rules like @media etc. The &lt;code&gt;@supports&lt;/code&gt; rule lets you to check the support for a CSS feature before the defined block of CSS properties are applied to the page. In other words its like saying that if “so and so” features are supported, apply these CSS properties to the page. Let’s take a look at an example usage of CSS &lt;code&gt;@supports&lt;/code&gt; rule.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@supports (display: flex) {
  .main-box { display:flex; padding:5px;}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the above code is parsed by the browser, it checks if the &lt;code&gt;display:flex&lt;/code&gt; property is supported by the browser, if so it takes into consideration the block of CSS wrapper within the &lt;code&gt;@supports&lt;/code&gt; rule. This can make your code simpler and lighter by avoiding the need for JavaScript for such feature detection. Interestingly, the &lt;code&gt;@supports&lt;/code&gt; rule has other Operators too which gives you a little more power while doing a feature detection.&lt;/p&gt;

&lt;h2&gt;
  
  
  Operators that &lt;code&gt;@supports&lt;/code&gt; support
&lt;/h2&gt;

&lt;p&gt;Similar to the media queries (@media), &lt;code&gt;@supports&lt;/code&gt; too has three operators :&lt;/p&gt;

&lt;h3&gt;
  
  
  The &lt;code&gt;not&lt;/code&gt; operator
&lt;/h3&gt;

&lt;p&gt;The “not” operator, as the name suggests, is to check for &lt;strong&gt;no support&lt;/strong&gt; of the specified CSS property. This can come in handy to write a fallback version. 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;@supports not (display: flex) {
  .main-box { display:inline-block; padding:5px;}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example we can notice that if the browser does not support &lt;code&gt;display:flex&lt;/code&gt; then keep the display as inline-block for the &lt;code&gt;.main-box&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  The &lt;code&gt;and&lt;/code&gt; operator
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;and&lt;/strong&gt; operator can be used to check if a certain property “and” some other property are supported. 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;@supports (display: flex) and (align-items: center;){
  .myDiv { display:flex; padding:5px;align-items: center;}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example the block of CSS would be rendered only if both the conditions are true. You can also combine the &lt;code&gt;and&lt;/code&gt; operator with &lt;code&gt;not&lt;/code&gt; operator. 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;@supports (display: inline-block) and (not (display:grid)){
  .myDiv { display:inline-block; padding:5px;}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The &lt;code&gt;or&lt;/code&gt; operator
&lt;/h3&gt;

&lt;p&gt;The other operator that &lt;code&gt;@supports&lt;/code&gt; support is the &lt;strong&gt;&lt;code&gt;or&lt;/code&gt;&lt;/strong&gt; operator. The &lt;code&gt;or&lt;/code&gt; operator as the name suggests can be used to check if any one of two or more CSS properties are supported by the browser. 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;@supports (display: flex) or (display: grid;){
  /* Block of CSS here */
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case the block of CSS would be executed even if one of the features are supported by the browser. You can use this operator to combine with the other operators too. 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;@supports not ((transform-style: preserve) or (-webkit-transform-style: preserve)) {
  /* Block of CSS here */
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you notice, we need to make use of parentheses properly in order to define the order in which they apply. Parentheses are especially important while using both &lt;code&gt;and&lt;/code&gt; and &lt;code&gt;or&lt;/code&gt; operators.&lt;/p&gt;

&lt;p&gt;To conclude I would say that the &lt;code&gt;@supports&lt;/code&gt; rule is a very useful and helpful feature in CSS. However, the older browsers including IE11 still do not support it, hence, you need to use this with caution. However, if you are not supporting older browsers then go for it. You can check for the Browser support at &lt;a href="https://caniuse.com/#feat=css-featurequeries"&gt;CanIUse.com&lt;/a&gt;. Let us know about your experience using it.&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://www.moreonfew.com/how-to-detect-support-for-a-css-feature-using-supports/"&gt;How to detect support for a CSS feature using @supports ?&lt;/a&gt; first appeared on &lt;a href="https://www.moreonfew.com"&gt;MoreOnFew&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>css</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>html</category>
    </item>
    <item>
      <title>How to make or convert LTR website to a RTL or Right-to-left Website?</title>
      <dc:creator>MoreOnFew</dc:creator>
      <pubDate>Wed, 05 Sep 2018 10:06:38 +0000</pubDate>
      <link>https://dev.to/moreonfew/how-to-make-or-convert-ltr-website-to-a-rtl-or-right-to-left-website-4dn7</link>
      <guid>https://dev.to/moreonfew/how-to-make-or-convert-ltr-website-to-a-rtl-or-right-to-left-website-4dn7</guid>
      <description>&lt;p&gt;I’m sure all of us want our websites to be visited and loved by people all over the world. And yes we would also like it to be shared on social media sites where people from all over the world would come across it. However many a time it might not strike to us that our visitors could be from countries that follow RTL(Right-To-Left) script. By RTL script I mean scripts of languages such as Arabic (العَرَبِية‎), Urdu ( &lt;strong&gt;اُردُو&lt;/strong&gt; ‎), Hebrew (עברית), Yiddish (יידיש) and so on where the reading and writing is done from Right to left unlike English and majority of other languages where the reading and writing of the script is done from Left to Right or LTR. So how do we make our website friendly to visitors following RTL languages? Well, that’s what I’m gonna tell you guys today, &lt;a href="https://www.moreonfew.com/how-to-convert-ltr-website-to-rtl-website/"&gt;how to convert your website from LTR to RTL&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to add RTL language support to a website?
&lt;/h2&gt;

&lt;p&gt;The most important thing to consider, When you add Right-To-Left or RTL Language support to your website, is to make a &lt;strong&gt;Mirror layout&lt;/strong&gt; of your website. That is, all the elements that were on the left would switch their position to the right. For example, take a look at the following image that has screenshots of the Yahoo US version (LTR) and Yahoo Middle East (RTL) version :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RvocRdOJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i1.wp.com/www.moreonfew.com/wp-content/uploads/2015/11/Mirror_Layout_website.jpg%3Fresize%3D700%252C600%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RvocRdOJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i1.wp.com/www.moreonfew.com/wp-content/uploads/2015/11/Mirror_Layout_website.jpg%3Fresize%3D700%252C600%26ssl%3D1" alt="Yahoo's LTR and RTL version" width="700" height="600"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Yahoo’s LTR and RTL version&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In the image above you can notice that all the elements or components on the page have switched their positions. The Logo which was on the left is now on the right side of the page. The search box and the button too have switched their positions, so have the carousel captions. Notice the side menu, that too has shifted to the right.&lt;/p&gt;

&lt;p&gt;Well, this might look a little weird to a reader who is used to LTR reading but it actually is very normal and ‘correct’ to a reader who is used to RTL. Hence it is quite important to be alert about how the components should be placed, for instance; the button comes before the text field and the label would come after the text box (well that’s what it would look like to a person used to LTR language).&lt;/p&gt;
&lt;h2&gt;
  
  
  So, What should I do to convert my site from LTR to RTL or right-to-left?
&lt;/h2&gt;

&lt;p&gt;You can &lt;a href="https://www.moreonfew.com/how-to-convert-ltr-website-to-rtl-website/"&gt;convert your website from left-to-right to right-to-left&lt;/a&gt; pretty easily than you would have thought it to be.&lt;/p&gt;
&lt;h3&gt;
  
  
  Convert html to rtl using the direction RTL property
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Firstly&lt;/strong&gt; , you need to change the direction of all the LTR elements to RTL. You can do this by using the &lt;code&gt;dir&lt;/code&gt; attribute of HTML. You can edit the &lt;code&gt;&amp;lt;html&amp;gt;&lt;/code&gt; tag to include &lt;code&gt;dir="rtl"&lt;/code&gt;. So your  tag should look similar to :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;html dir="rtl"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Right to left CSS considerations
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Secondly&lt;/strong&gt; , you need to change the direction sensitive CSS properties to suit the RTL design flow. In other words, the values of direction sensitive CSS properties like margin, padding, float, background-position, border-left etc needs to be edited. For example, say I have a property in CSS like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; margin: 0 0 10px 20px; /* (i.e margin:top right bottom left) */
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;this needs to be changed to&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;margin:0 20px 10px 0; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you notice, we swapped the margin-right value with the margin-left value. This needs to be done for all the direction sensitive CSS properties. Here is a list of all the direction sensitive CSS properties:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Direction Sensitive CSS Properties&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;background&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;background-image&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;background-position&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;background-position-x&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;border-bottom-left-radius&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;border-bottom-right-radius&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;border-color&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;border-left&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;border-left-color&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;border-left-style&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;border-left-width&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;border-radius&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;border-right&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Thirdly&lt;/strong&gt; , By now your page would be 90% RTL already ! However, you might still notice pieces of components broken which might require you to inspect and edit the CSS values based on the First and Second steps.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tools to automatically convert CSS from LTR to RTL
&lt;/h3&gt;

&lt;p&gt;While you can manually convert the CSS to meet the RTL requirement, there are many tools that you can use too. I’m listing down a couple of them:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/twitter/css-flip"&gt;CSS FLIP&lt;/a&gt; : CSS FLIP is a project by Twitter that helps you to convert your LTR CSS to RTL. You can install it via npm using &lt;code&gt;npm install css-flip&lt;/code&gt;. To generate the rtl css you can use use their CLI and run the command as &lt;code&gt;css-flip path/to/file.css &amp;gt; path/to/file.rtl.css&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/MohammadYounes/rtlcss"&gt;RTL CSS&lt;/a&gt; : RTL CSS also provides features similar to CSS FLIP. You can install it using npm code &lt;code&gt;npm install -g rtlcss&lt;/code&gt;. You can also use it along with PostCSS etc or you can also use their CLI and run the command &lt;code&gt;rtlcss input.css output.rtl.css&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://cssjanus.github.io/"&gt;CSSJanus&lt;/a&gt; : CSSJanus is an online tool where you can copy paste your ltr CSS to convert it into RTL CSS. Its a good tool if you do not want to go through the hassle of installing packages or if you don’t want to use node packages.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://rtl.daskhat.ir/"&gt;Rastchin&lt;/a&gt; : Rastchin is another online LTR to RTL CSS converter which is similar to CSSJanus but also provides few more options like generating minified RTL CSS output, linting the LTR CSS etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While there are many tools available to convert LTR CSS to RTL, I would recommend that you first understand what steps do you need to take to &lt;a href="https://www.moreonfew.com/how-to-convert-ltr-website-to-rtl-website/"&gt;convert your LTR website or CSS to RTL&lt;/a&gt; and also the best possible way to do so. It could be manual, using tools or many be a mix of both as I believe even after using the tools, the outcome might not be 100% accurate as you wanted it to be and hence you might have to edit some components manually. Anyway, let us know about your experience of converting your LTR website to RTL.&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://www.moreonfew.com/how-to-convert-ltr-website-to-rtl-website/"&gt;How to make or convert LTR website to a RTL or Right-to-left Website?&lt;/a&gt; first appeared on &lt;a href="https://www.moreonfew.com"&gt;MoreOnFew&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>tutorial</category>
      <category>html</category>
      <category>css</category>
    </item>
  </channel>
</rss>
