Sign in
Log inSign up
Tapas Adhikary

25 comments

Jatin Rao
Jatin Rao
Jul 28, 2020

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

6
·
·1 reply
Christopher Norris
Christopher Norris
Oct 24, 2022

This is fantastic and useful.

·
Sandeep Panda Test
Sandeep Panda Test
Jul 28, 2020

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. 🙏

4
·
·1 reply
Tapas Adhikary
Tapas Adhikary
Author
·Jul 28, 2020

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.. 😊

·
Simon Scarfe
Simon Scarfe
Aug 1, 2020

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/JavaS…

3
·
·1 reply
Tapas Adhikary
Tapas Adhikary
Author
·Aug 1, 2020

Hey Simon,

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

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

1
·
Shubham Kumar
Shubham Kumar
Oct 26, 2021

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

3
·
·1 reply
Tapas Adhikary
Tapas Adhikary
Author
·Oct 26, 2021

You are welcome, Shubham Kumar

·
Bolaji Ayodeji
Bolaji Ayodeji
Jul 28, 2020

This is really amazing, thanks for sharing!

2
·
·1 reply
Tapas Adhikary
Tapas Adhikary
Author
·Jul 28, 2020

Thanks Bolaji!

·
Rutik Wankhade
Rutik Wankhade
Jul 28, 2020

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

2
·
Victoria Lo
Victoria Lo
Jul 28, 2020

Another legendary article born from Mr. Tapas Adhikary's fingers! Thanks!

2
·
Luiz Filipe da Silva
Luiz Filipe da Silva
Jul 28, 2020

Amazing tricks! Thanks for sharing 🤠🚀

2
·
Faith Gaiciumia
Faith Gaiciumia
Jul 29, 2020

Thanks a lot for this

2
·
Afraz Momin
Afraz Momin
Jul 29, 2020

Very helpful article Tapas. Thank you 🙏

2
·
Federico Kereki
Federico Kereki
Jul 31, 2020

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.

2
·
·1 reply
Tapas Adhikary
Tapas Adhikary
Author
·Aug 1, 2020

Federico Kereki, 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.

·
Pankaj Patel
Pankaj Patel
Aug 2, 2020

Cool collection of JS tricks

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

Good job Tapas

2
·
Hayden Chambers
Hayden Chambers
Oct 21, 2020

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

2
·
·1 reply
Tapas Adhikary
Tapas Adhikary
Author
·Oct 21, 2020

Thanks Hayden Chambers! I remember noticing that but didn't update due to my laziness.. I just did that.

Appreciate you reading and commenting.

·
Imran Pollob
Imran Pollob
Jan 24, 2021

great

2
·
Gerardo Cardenas
Gerardo Cardenas
Oct 5, 2020

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

·
·3 replies
Tapas Adhikary
Tapas Adhikary
Author
·Oct 6, 2020

Hi Gerardo Cardenas, Thanks for reading and commenting.

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

image.png

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

·
Gerardo Cardenas
Gerardo Cardenas
Oct 6, 2020

I am sorry, i did not read correctly maybe. Best regards Tapas Adhikary

2
·
Tapas Adhikary
Tapas Adhikary
Author
·Oct 7, 2020

Gerardo Cardenas, Not a problem at all. Thanks for reading.

·