139 likes
·
19.2K reads
25 comments
Whoa! This post is a Treasure 🥇 Thanks for sharing 🧡
This is fantastic and useful.
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. 🙏
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.. 😊
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…
Hey Simon,
Thank you very much for liking it and the encouraging words.
You got a great point about the defaults.. Thanks, really appreciate!
Wow, this is awesome, Thank you so much for sharing this
You are welcome, Shubham Kumar
This is really amazing, thanks for sharing!
Thanks Bolaji!
These are some great tricks. Thanks for sharing. Bookmarked 👍
Another legendary article born from Mr. Tapas Adhikary's fingers! Thanks!
Amazing tricks! Thanks for sharing 🤠🚀
Thanks a lot for this
Very helpful article Tapas. Thank you 🙏
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.
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.
Cool collection of JS tricks
I like the isRequired
trick as it is simply claver and very useful.
Good job Tapas
The default value example isn't the best.. If Jack has just been born he's suddenly 35
Thanks Hayden Chambers! I remember noticing that but didn't update due to my laziness.. I just did that.
Appreciate you reading and commenting.
great
I think that the output is incorrect of the bullet number 11: let [fruit, ...rest] = emojis; console.log(rest);
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.
It would be great, if you could check it and let me know, I would be glad to correct it.
I am sorry, i did not read correctly maybe. Best regards Tapas Adhikary
Gerardo Cardenas, Not a problem at all. Thanks for reading.