---
title: "Discussion on \"My Favorite JavaScript Tips and Tricks\" | Hashnode"
description: "Discussion on \"My Favorite JavaScript Tips and Tricks\". Motivation\nMost of the programming languages are open enough to allow programmers to do things multiple ways for a similar outcome. JavaScript is in no way different. With JavaScript, we often find multiple ways of doing things for a similar outcome,..."
url: "https://hashnode.com/posts/my-favorite-javascript-tips-and-tricks/5f203086ba06442180226d0f"
---

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

Discussion

# [My Favorite JavaScript Tips and Tricks](https://blog.greenroots.info/my-favorite-javascript-tips-and-tricks?utm_source=hashnode&utm_medium=feed)

Motivation Most of the programming languages are open enough to allow programmers to do things multiple ways for a similar outcome. JavaScript is in no way different. With JavaScript, we often find multiple ways of doing things for a similar outcome,...

Jul 28, 2020 · 15 min read · blog.greenroots.info  
Updated Feb 2, 2021  
Read the article

-   [#2articles1week](https://hashnode.com/tag/2articles1week)
-   [#javascript](https://hashnode.com/tag/javascript)
-   [#web-development](https://hashnode.com/tag/web-development)
-   [#beginner](https://hashnode.com/tag/beginner)
-   [#tips](https://hashnode.com/tag/tips)

## Written by

[Tapas Adhikary](https://hashnode.com/@atapas)

@atapas · Bangalore

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

Educator @tapaScript | Founder CreoWis & ReactPlay - Writer - YouTuber - Open Source

Co-Founder, @CreoWis | Teacher, @tapaScript | Founder, @ReactPlay | YouTuber | Writer | Human

## Responses 15

Markdown supported · ⌘↵ to post

[Shubham Kumar](https://hashnode.com/@Shubhham)

[Oct 26, 2021](https://hashnode.com/posts/my-favorite-javascript-tips-and-tricks/5f203086ba06442180226d0f/comment/6177a6c30f452c1cd94fdcd5)

Wow, this is awesome, Thank you so much for sharing this

[Tapas Adhikary](https://hashnode.com/@atapas)

[Oct 26, 2021](https://hashnode.com/posts/my-favorite-javascript-tips-and-tricks/5f203086ba06442180226d0f/comment/6177a6c30f452c1cd94fdcd5#reply-6177a7b9fc34737bf9ab6fa6)

You are welcome, [Shubham Kumar](https://hashnode.com/@Shubhham)

[Imran Pollob](https://hashnode.com/@imranpollob)

[Jan 24, 2021](https://hashnode.com/posts/my-favorite-javascript-tips-and-tricks/5f203086ba06442180226d0f/comment/600d88503b349540feb9ed75)

great

[Hayden Chambers](https://hashnode.com/@HaydenChambers)

[Oct 21, 2020](https://hashnode.com/posts/my-favorite-javascript-tips-and-tricks/5f203086ba06442180226d0f/comment/5f8ff097f2119b4f9e0ce025)

The default value example isn't the best.. If Jack has just been born he's suddenly 35

[Tapas Adhikary](https://hashnode.com/@atapas)

[Oct 21, 2020](https://hashnode.com/posts/my-favorite-javascript-tips-and-tricks/5f203086ba06442180226d0f/comment/5f8ff097f2119b4f9e0ce025#reply-5f8ff418f2119b4f9e0ce070)

Thanks [Hayden Chambers](https://hashnode.com/@HaydenChambers)! I remember noticing that but didn't update due to my laziness.. I just did that.

Appreciate you reading and commenting.

[Gerardo Cardenas](https://hashnode.com/@AmateurProgrammer)

[Oct 5, 2020](https://hashnode.com/posts/my-favorite-javascript-tips-and-tricks/5f203086ba06442180226d0f/comment/5f7b79659d088e603ef39596)

I think that the output is incorrect of the bullet number 11: let \[fruit, ...rest\] = emojis; console.log(rest);

[Tapas Adhikary](https://hashnode.com/@atapas)

[Oct 6, 2020](https://hashnode.com/posts/my-favorite-javascript-tips-and-tricks/5f203086ba06442180226d0f/comment/5f7b79659d088e603ef39596#reply-5f7be0a5e93896601dd2911a)

Hi [Gerardo Cardenas](https://hashnode.com/@AmateurProgrammer), Thanks for reading and commenting.

To understand the comment better, I have tried it again and found the output to be correct.

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1601953924055/Q2KWlQjmN.png)

It would be great, if you could check it and let me know, I would be glad to correct it.

[Gerardo Cardenas](https://hashnode.com/@AmateurProgrammer)

[Oct 6, 2020](https://hashnode.com/posts/my-favorite-javascript-tips-and-tricks/5f203086ba06442180226d0f/comment/5f7b79659d088e603ef39596#reply-5f7cd38294f39f6ab9fbf741)

I am sorry, i did not read correctly maybe. Best regards [Tapas Adhikary](https://hashnode.com/@atapas)

[Tapas Adhikary](https://hashnode.com/@atapas)

[Oct 7, 2020](https://hashnode.com/posts/my-favorite-javascript-tips-and-tricks/5f203086ba06442180226d0f/comment/5f7b79659d088e603ef39596#reply-5f7d3164eba2f86adc0b6334)

[Gerardo Cardenas](https://hashnode.com/@AmateurProgrammer), Not a problem at all. Thanks for reading.

[Pankaj Patel](https://hashnode.com/@pankajpatel)

[Aug 2, 2020](https://hashnode.com/posts/my-favorite-javascript-tips-and-tricks/5f203086ba06442180226d0f/comment/5f26923890ac4260edf35cb6)

Cool collection of JS tricks

I like the `isRequired` trick as it is simply claver and very useful.

Good job [Tapas](https://hashnode.com/@atapas)

[Simon Scarfe](https://hashnode.com/@si)

[Aug 1, 2020](https://hashnode.com/posts/my-favorite-javascript-tips-and-tricks/5f203086ba06442180226d0f/comment/5f255e52669da9610ee17812)

Great list - lots of lovely little tidbits, especially the `isRequired` helper function. Love that!

You have to be slightly careful with the default or in 5, though. If `age` is 0, it will overwrite it (making your new born person object a 35 year old 😉).

A safer, albeit slightly less-well-supported (IE doesn't know about it), way of attacking it is to use the nullish coalescing operator - `??` which returns truthy values such as 0.

More info available on MDN: [developer.mozilla.org/en-US/docs/Web/JavaScript/R…](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_operator)

[Tapas Adhikary](https://hashnode.com/@atapas)

[Aug 1, 2020](https://hashnode.com/posts/my-favorite-javascript-tips-and-tricks/5f203086ba06442180226d0f/comment/5f255e52669da9610ee17812#reply-5f256440669da9610ee1784a)

Hey Simon,

Thank you very much for liking it and the encouraging words.

You got a great point about the defaults.. Thanks, really appreciate!

[Federico Kereki](https://hashnode.com/@fkereki)

[Jul 31, 2020](https://hashnode.com/posts/my-favorite-javascript-tips-and-tricks/5f203086ba06442180226d0f/comment/5f24551f90ac4260edf34841)

I'm not sure about the random function, because of the rounding. Check it out: I believe that the min and max values aren't produced as often the other ones.

[Tapas Adhikary](https://hashnode.com/@atapas)

[Aug 1, 2020](https://hashnode.com/posts/my-favorite-javascript-tips-and-tricks/5f203086ba06442180226d0f/comment/5f24551f90ac4260edf34841#reply-5f24c5ba669da9610ee17377)

[Federico Kereki](https://hashnode.com/@fkereki), Thanks!

Yes, the floor function has surely got more chances of producing randoms than round, I believe. Appreciate your feedback and thanks for reading through.

[Afraz Momin](https://hashnode.com/@afrazmomin)

[Jul 29, 2020](https://hashnode.com/posts/my-favorite-javascript-tips-and-tricks/5f203086ba06442180226d0f/comment/5f215342938147308462a2d9)

Very helpful article [Tapas](https://hashnode.com/@atapas). Thank you 🙏

[Faith Gaiciumia](https://hashnode.com/@shumia)

[Jul 29, 2020](https://hashnode.com/posts/my-favorite-javascript-tips-and-tricks/5f203086ba06442180226d0f/comment/5f214adf938147308462a2a8)

Thanks a lot for this

[Luiz Filipe da Silva](https://hashnode.com/@luizfilipezs)

[Jul 28, 2020](https://hashnode.com/posts/my-favorite-javascript-tips-and-tricks/5f203086ba06442180226d0f/comment/5f206c5eba0644218022709d)

Amazing tricks! Thanks for sharing 🤠🚀

[Victoria Lo](https://hashnode.com/@victoria)

[Jul 28, 2020](https://hashnode.com/posts/my-favorite-javascript-tips-and-tricks/5f203086ba06442180226d0f/comment/5f205beeba06442180226f7e)

Another legendary article born from Mr. [Tapas Adhikary](https://hashnode.com/@atapas)'s fingers! Thanks!

[Jatin Rao](https://hashnode.com/@jatinrao)

[Jul 28, 2020](https://hashnode.com/posts/my-favorite-javascript-tips-and-tricks/5f203086ba06442180226d0f/comment/5f205527ed20ff21a11e7823)

Whoa! This post is a Treasure 🥇 Thanks for sharing 🧡

[Christopher Norris](https://hashnode.com/@afrpar)

[Oct 24, 2022](https://hashnode.com/posts/my-favorite-javascript-tips-and-tricks/5f203086ba06442180226d0f/comment/5f205527ed20ff21a11e7823#reply-63560fe4499ee6e7154b7b42)

This is fantastic and useful.

[Rutik Wankhade](https://hashnode.com/@rutikwankhade)

[Jul 28, 2020](https://hashnode.com/posts/my-favorite-javascript-tips-and-tricks/5f203086ba06442180226d0f/comment/5f204f8bed20ff21a11e77c7)

These are some great tricks. Thanks for sharing. Bookmarked 👍

[Sandeep Panda](https://hashnode.com/@sandeep)

[Jul 28, 2020](https://hashnode.com/posts/my-favorite-javascript-tips-and-tricks/5f203086ba06442180226d0f/comment/5f2033d7ed20ff21a11e768e)

Wow! Such a wonderful list. We should pin it somewhere and force every JavaScript developer to go through this. 😎

`event.target.valueAsNumber`: I never knew about this neat trick! Learned something new!

I also found `isRequired` check very clever.

Thanks for writing this article. It's a treausure. 🙏

[Tapas Adhikary](https://hashnode.com/@atapas)

[Jul 28, 2020](https://hashnode.com/posts/my-favorite-javascript-tips-and-tricks/5f203086ba06442180226d0f/comment/5f2033d7ed20ff21a11e768e#reply-5f20358ced20ff21a11e76ad)

Thanks Sandeep! I am very glad, it was useful to you.

I am not sure, how many such tricks we discover, find or learn from others on daily basis. When I sat down and looked through some project code written in recent past, I found these I have used but never documented any better ways. Thought of doing that today.. 😊

[Bolaji Ayodeji](https://hashnode.com/@bolajiayodeji)

[Jul 28, 2020](https://hashnode.com/posts/my-favorite-javascript-tips-and-tricks/5f203086ba06442180226d0f/comment/5f203264ed20ff21a11e766e)

This is really amazing, thanks for sharing!

[Tapas Adhikary](https://hashnode.com/@atapas)

[Jul 28, 2020](https://hashnode.com/posts/my-favorite-javascript-tips-and-tricks/5f203086ba06442180226d0f/comment/5f203264ed20ff21a11e766e#reply-5f2035a5ed20ff21a11e76b1)

Thanks Bolaji!
