javascript

Various loops available in javascript

Gagandeep Singh
This post will focus on the various loops available in the javascript and when to use them. for - Probably the most commonly used loop in any programming language. The for loop runs until a specific condition is true. As seen below, it has 3 parts: i) initialization (i=0) ii) condition (i<5) iii) increment/decrement (i++/i--) for (let i = 0; i < 5; i++) { console.log(i); } for (let i = 5; i >= 0; i--) { console.

useCallback vs useMemo

Gagandeep Singh
useCallback and useMemo are two of the multiple hooks released with React V16. Hooks are javascript functions which help in isolating some functionality from the functional component (hooks cannot be used inside class based components). useCallback - As per the official documents, useCallback “Returns a memoized callback”. Here memoized means maintaining or saving a version of the function in the memory for the given array of one or more dependencies.

Different console methods in Javascript

Gagandeep Singh
There are few console methods available in Javascript, console.log being the most common one. Each of these variations of console methods could and should be used depending on type of data to output. console.log() - As mentioned earlier console.log() is the most common console method and can be used to output any kind of data. console.log(); const message = "Hello world"; const num1 = 10; const num2 = 20; console.

Create a globally executable javascript file

Gagandeep Singh
We will understand and see how to create an executable javascript file using a global command. Lets say for example you want to create a clone of ‘ls’ or ‘cmd’ command which shows the content of the current folder or from the path provided. To acheive that we need to have a global command. To acheive this we need to do couple of things and need to have 2 files (index.

Using pre-commit hook in package.json

Gagandeep Singh
One of the traits of someone who follows or moving towards a good coding practice environment is making sure that you are not pushing the code which may have linting issues and/or failing unit tests. Adding a pre-commit hook forces to check the lint and run unit tests (or any other script) to be sure that everything is good before committing changes. npm i --save-dev pre-commit Next step is to update the package.