---
title: "Discussion on \"JavaScript Tips and Best Practices\" | Hashnode"
description: "Discussion on \"JavaScript Tips and Best Practices\". In this article, I’ll share 10 of the JavaScript tips, tricks & best practices that should be known by all JavaScript developers"
url: "https://hashnode.com/posts/javascript-tips-and-best-practices/60e17cd303707d644a5022e6"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [JavaScript Tips and Best Practices](https://apoorvtyagi.tech/javascript-tips-and-best-practices?utm_source=hashnode&utm_medium=feed)

In this article, I’ll share 10 of the JavaScript tips, tricks & best practices that should be known by all JavaScript developers

Jul 4, 2021 · 6 min read · apoorvtyagi.tech  
Updated Oct 12, 2022  
Read the article

-   [#javascript](https://hashnode.com/tag/javascript)
-   [#web-development](https://hashnode.com/tag/web-development)
-   [#typescript](https://hashnode.com/tag/typescript)
-   [#programming-tips](https://hashnode.com/tag/programming-tips)
-   [#programming](https://hashnode.com/tag/programming)

## Written by

[Apoorv Tyagi](https://hashnode.com/@apoorvtyagi)

@apoorvtyagi · India

  
[View profile](https://hashnode.com/@apoorvtyagi)

Senior Software Engineer | Tech Blogger | !(Chess GM)

Senior Software Engineer. I write about practical tips and epic stories about my experiences in the field of computer science and engineering!

## Responses 5

Markdown supported · ⌘↵ to post

[Николай Коваленко](https://hashnode.com/@Nikolai)

[Jul 4, 2021](https://hashnode.com/posts/javascript-tips-and-best-practices/60e17cd303707d644a5022e6/comment/60e2130b4f8e376422a7aa85)

if (\[1, 'one', 2, 'two'\].includes(value)) {

}

It creates new array every time. It is slower than multiple values comparison

[Николай Коваленко](https://hashnode.com/@Nikolai)

[Jul 5, 2021](https://hashnode.com/posts/javascript-tips-and-best-practices/60e17cd303707d644a5022e6/comment/60e2130b4f8e376422a7aa85#reply-60e318a94f8e376422a7c532)

[Apoorv Tyagi](https://hashnode.com/@apoorvtyagi) make a loop of 1000 and compare durations

[Николай Коваленко](https://hashnode.com/@Nikolai)

[Jul 5, 2021](https://hashnode.com/posts/javascript-tips-and-best-practices/60e17cd303707d644a5022e6/comment/60e2130b4f8e376422a7aa85#reply-60e31aa94f8e376422a7c55d)

[Apoorv Tyagi](https://hashnode.com/@apoorvtyagi)

const value = 1; const start = performance.now(); for(let i = 0; i<100000; i++) { if (\[1, 'one', 2, 'two'\].includes(value)) {

} }

console.log(performance.now() - start);

const start2 = performance.now(); for(let i = 0; i<100000; i++) { if (value === 1 || value === 'one' || value === 2 || value === 'two') {

} }

console.log(performance.now() - start2);

Second is 2 times faster

[Apoorv Tyagi](https://hashnode.com/@apoorvtyagi)

[Jul 6, 2021](https://hashnode.com/posts/javascript-tips-and-best-practices/60e17cd303707d644a5022e6/comment/60e2130b4f8e376422a7aa85#reply-60e3c6f94aacd630482416f2)

Thanks [Николай Коваленко](https://hashnode.com/@Nikolai) I Will check this.

[D S](https://hashnode.com/@dstutts-dev)

[Jul 4, 2021](https://hashnode.com/posts/javascript-tips-and-best-practices/60e17cd303707d644a5022e6/comment/60e1ec9103707d644a5033bb)

Solid Article! The only qualm I'll take is with #5 as it seems junior level devs already overuse `.map()`. `.forEach()` is a more analogous solution vs a `for loop`. Map, filter, and reduce have their applications and are really nice for, like you said, one lining code, but I feel map in particular is overused.

[Apoorv Tyagi](https://hashnode.com/@apoorvtyagi)

[Jul 4, 2021](https://hashnode.com/posts/javascript-tips-and-best-practices/60e17cd303707d644a5022e6/comment/60e1ec9103707d644a5033bb#reply-60e1eea103707d644a503449)

Thanks [D S](https://hashnode.com/@dstutts-dev).

I totally get your point here. In my opinion, in most cases it depends on your use case.

`map()` creates a new array populated with the results of calling a function on every element in the calling array whereas `forEach()` method executes a provided function once for each array element.

So Basically, if you want to obtain a modified form of the previous array, you can sure short go for `map()`, if you don’t want that, you use `forEach()`

[Niranjan Borawake](https://hashnode.com/@niranjandb)

[Jul 4, 2021](https://hashnode.com/posts/javascript-tips-and-best-practices/60e17cd303707d644a5022e6/comment/60e1ec9103707d644a5033bb#reply-60e1fb5403707d644a5035e2)

[Apoorv Tyagi](https://hashnode.com/@apoorvtyagi) This is so true. I have infact explicitly written about it - [When not to use map](https://blog.niranjanborawake.in/when-not-to-use-array-prototype-map)

[Apoorv Tyagi](https://hashnode.com/@apoorvtyagi)

[Jul 4, 2021](https://hashnode.com/posts/javascript-tips-and-best-practices/60e17cd303707d644a5022e6/comment/60e1ec9103707d644a5033bb#reply-60e1fbf903707d644a5035fc)

[Niranjan Borawake](https://hashnode.com/@niranjandb) Great explanation Thanks for sharing

[CHris](https://hashnode.com/@tooshort06)

[Jul 4, 2021](https://hashnode.com/posts/javascript-tips-and-best-practices/60e17cd303707d644a5022e6/comment/60e1bf214f8e376422a79999)

Very informative tips and tricks thanks!

[Apoorv Tyagi](https://hashnode.com/@apoorvtyagi)

[Jul 4, 2021](https://hashnode.com/posts/javascript-tips-and-best-practices/60e17cd303707d644a5022e6/comment/60e1bf214f8e376422a79999#reply-60e1c0b94f8e376422a799b8)

You're welcome [CHris](https://hashnode.com/@tooshort06)!

Glad you like them😀

[Kamil Gierach-Pacanek](https://hashnode.com/@Asentinn)

[Jul 4, 2021](https://hashnode.com/posts/javascript-tips-and-best-practices/60e17cd303707d644a5022e6/comment/60e1919303707d644a50255e)

Didn't know about `console.table`!

[Apoorv Tyagi](https://hashnode.com/@apoorvtyagi)

[Jul 4, 2021](https://hashnode.com/posts/javascript-tips-and-best-practices/60e17cd303707d644a5022e6/comment/60e1919303707d644a50255e#reply-60e1abe04f8e376422a797c0)

It's not very significant but yeah, something new and different which is good to know :)
