Top 10 Handy JavaScript Tips To Know 
Tags: javascript, beginners, programming, arrays
Published: 2022-02-23 00:19:06

This blog was inspired by [David Arias Fuentes](https://twitter.com/devarias_/status/1495446577879658499?s=20&t=jE8yIjDBzf8tyclPjlU_vg)' tweet: "15 Magical JavaScript Tips for Every Web Developer". I loved it so much, I had to share it with my network. I had DM'ed him beforehand before publishing this post. Please follow him for more helpful posts! 

![How handy!](https://media.giphy.com/media/clEONqsy81tAMluJUA/giphy.gif)


**1. Flatten the array of the array**

This tip will help you to flatten a deeply nested array of arrays by using Infinity in flat.

![Flatten the array](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/od2s7tyrnbfr926ahc99.png)

**2. Easy Exchange Variables**

You probably swap the two variables using a third variable temp. But this tip will show you a new way to exchange variables using destructuring.

![Easy Exchages](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kqzxw1ndz7rltgw7qhr6.png)

**3. Sort Alphabetically**

Sorting is a common problem in programming, and this tip will save your valuable time by writing a long code to sort a string alphabetically.


![Sort Alphabetically](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ayp7g6fd54n24jpii6dq.png)

**4. Generate Range of Numbers**

Suppose you want to generate a number between a specific range. The first approach you will use is the loop. But this tip will save you valuable time by doing it the easy way.


![Range of Numbers](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iff8szxxlqzktmnp5gzf.png)

**5. Shorten the Console log**

Tired of writing console.log() again and again? This tip will show how to shorter your console log and speed up your coding.

![Shorten console.log](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jvvf05v8ft5e4i71pg0x.png)

**6. Shortening an Array in an easy way**

This is an awesome tip for web developers to shorten an array in an easy way. You just need to use the length method by passing a number that denotes the new size of your array.

![Shorten array](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rcm79hu1mm5p97l5uu5s.png)

**7. Use isNumber**

This tip will show how to check whether a value or variable holding a number ( integer, float and etc ) or not.


![isNumber](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/50qyw54aiwu332y95xfv.png)

**8. Use isString**

This useful tip will show you how to check whether a value or data is in string format or not. This comes in handy when you request data from the server and want to check the data type.


![isString](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e0no14fp04phko5dd9w5.png)

**9. Check Null**

In Programming, sometimes we need to check whether a result or data is null.


![Null](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4fxf99dxk9weap9mm51k.png)

**10. Merge Array into One**

This tip will be useful when you need to combine the two arrays of any size into one. You need to use the JavaScript concate method for this.

![Merge Array](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bqkoq7q003axdbkz4yzh.png)

_Cover photo: Caspar Camille Rubin @casparrubin_

![Ok, bye!](https://media.giphy.com/media/26u3Zl2MQWJl2hf2g/giphy.gif)