What is the difference between npm and yarn ?

  • NPM stands for Node Package Manager.
  • YARN stands for Yet Another Resource Negotiator.
  • Both NPM and YARN are package managers for public or private packages.
  • YARN was developed by Facebook to fix performance and security issues with npm.
  • NPM generates package-lock.json file
  • YARN generates yarn.lock file
  • NPM installs dependencies Sequentially.
  • YARN installs dependencies parellelly.
  • NPM maintains global package cache, which stores downloaded packages. This global cache shares across all projects, which saves disk space and reduce redundant downloads.
  • YARN maintains cache for each project seperately. Which increases reliability and ensures consistent package versions.

typeError: cannot read properties of undefined (reading ‘join’)

  1. We should apply the join method only on Array. So before applying the join method, first we need to check that the output is coming in the form of array or not.
  2. if you are using any online code editor, check that you should use return instead of console.log. May be in the background they are applying the join method. So, for that they don’t want log reports. We need to return the output and the output should be in the form of Array to apply the Join method.

Mock a function or setState using jest in ReactJS.

lets assume that we need to mock setStatus(). So, in test file we will mock by using jest as follows.

Displaying comma separated elements using map function from Array of Objects – ReactJS

lets take an example of the following Array

lets use map function to display names of class-5 in the same row.

if we use .toString() to the map function, comma separated names will display.

Converting time from 12-hour AM/PM format to 24-hour format without AM/PM – JavaScript

By using toLocaleTimeString() :

Explanation : 

1. time = "11:40:22 PM"
2. date = 2022-01-01T23:40:22.000Z (we can give any date as we are converting only time)
3. formattedTime = 23:40:22 ("en-GB" means 24-hour time without AM/PM)