JavaScript Tips and Tricks
Tags: javascript, tips
Published: 2023-11-18 23:15:58


## JavaScript Tips and Tricks

![](https://cdn-images-1.medium.com/max/4120/1*06Q7HHp3ppGAdrIFwNVDVg.jpeg)

As you know, JavaScript is the number one programming language in the world, the language of the web, of mobile hybrid apps (like [React Native](https://reactnative.dev/)), of the server side (like [NodeJS](https://nodejs.org/en/) ) and has many other implementations. It’s also the starting point for many new developers to the world of programming, as it can be used to display a simple alert in the web browser but also to control a robot (using [nodebot](https://nodebots.io/), or nodruino). The developers who master JavaScript and write organized and performant code have become the most sought after in the job market.

In this article, I’ll share a set of JavaScript tips, tricks and best practices that should be known by all JavaScript developers regardless of their browser/engine or the SSJS (Server Side JavaScript) interpreter.

## **use **=== **instead of **==

The == (or !=) operator performs an automatic type conversion if needed. The === (or !==) operator will not perform any conversion. It compares the value and the type, which could be considered faster than ==.

![](https://cdn-images-1.medium.com/max/2312/1*5j2S_Ot3LJmeMrISerV0CQ.png)
>  undefined, null, 0, false, NaN, ‘’(empty string) are all falsy.

## Find max and min from an array

The traditional way to find min and max is loop through each element of array and find min and max. Below code snippet is showing to find min and max from array using spread operator.

![](https://cdn-images-1.medium.com/max/2000/1*gJ1aYxHa5cjJD5WipPxbLQ.png)

## Merging two arrays

![](https://cdn-images-1.medium.com/max/2420/1*IiNhQA0SQtpnAxqTAIRv8A.png)

## Repeating string multiple times

![](https://cdn-images-1.medium.com/max/2000/1*8iFhY9LwId80tXP6Wqxf0A.png)

## String to Number conversion

![](https://cdn-images-1.medium.com/max/2000/1*2ENDkJr_JbrmJtYSggZ3Rw.png)

## Multiple variable assignments

![](https://cdn-images-1.medium.com/max/2000/1*polManQb7avrsOb-o-W2Jw.png)

## Multiple condition check

![](https://cdn-images-1.medium.com/max/3132/1*YU67GcqRmuS74MM8HNzDVw.png)

## Remove duplicates from an array

![](https://cdn-images-1.medium.com/max/2624/1*_gEXMCTT80a7GJBCpHmZ1A.png)

## Sum the values of an array

![](https://cdn-images-1.medium.com/max/2136/1*0MkwswVNT92WWb8le1HdYg.png)

## Convert a string to an array

![](https://cdn-images-1.medium.com/max/2456/1*i26ZtsiEaVnR4pBdo-N6Dg.png)

## Remove falsey values from an array

![](https://cdn-images-1.medium.com/max/3232/1*6_qYZQGMWFV2dQnk5FTWVg.png)

## Alternatives of for loop

![](https://cdn-images-1.medium.com/max/2000/1*DBCKNd9VHlKQPt14fxhuPA.png)

## OR Short circuit

![](https://cdn-images-1.medium.com/max/2792/1*jaRFy9Zi8lSE4uE0brDmRw.png)

## AND Short circuit

![](https://cdn-images-1.medium.com/max/2928/1*Tj0La0eChDoLdl7wlDd0QQ.png)

## Exponent power

![](https://cdn-images-1.medium.com/max/2000/1*bUPRweugl3OZwskfeoJKhA.png)

## Count function parameters

![](https://cdn-images-1.medium.com/max/2000/1*s_Hu-wHUoEAkUngBgyzDTQ.png)

## Assign default function parameter

![](https://cdn-images-1.medium.com/max/2220/1*U03MFq79zxo7rjIUjgBOxA.png)

Check if key exists in the object

![](https://cdn-images-1.medium.com/max/2604/1*56cGx2ErQ0nTHeawQi9Pvw.png)

## Object property assignment

![](https://cdn-images-1.medium.com/max/3636/1*TwflyJ8BiQACWznFKKMEig.png)

## Assigning object value property to a variable

![](https://cdn-images-1.medium.com/max/2220/1*qeS6GEGANg1uNpz1A6TzjA.png)

## Removing multiple properties from an object

![](https://cdn-images-1.medium.com/max/2084/1*cjaz3KW-h0cIzxMaVeqq-w.png)

Here are my two bits of contribution in JavaScript community. I hope these code snippets will help someone to learn some tips and tricks in JavaScript.