Hi JS-heroes! Finally done with this new article! Let's go ahead ✨
1. Generate a list with random numbers
We need A LOT of fake data, f...
For further actions, you may consider blocking this person and/or reporting abuse
One that I love is this:
The or operator works the same as an elvis operator.
This is useful if you want to display a default value when you can't get data from an api or if some data is null for a key.
This can be chained with objects
Love this one too, it's also useful to prevent errors when destructuring something that could be undefined:
This can prevent errors such as "Cannot read foo of undefined".
With ES2021 we have
||=
:)Which makes the syntax even cooler
I made a video about new features here:
youtu.be/hxmFYToenxE
True but not fully supported yet
With the right babelJS version it is ;)
And then you're bringing big pieces of extra code for not much 😉 good way to slow websites.
I would say that developer convenience is more than a lot. Also, few bytes of code for polyfill, definitely will not slow down the website.
I tend to think of client first. UX is more important than writing one word less. for a developer. between users having slow internet speeds, limited networks and not the greatest machines bringing one poly-fill here and there vs zero can make a huge difference. If you are making something just for you or limited public then why not but the difference in code between the statement I used vs using
||=
is not that big that it would justify using a poly-fill on my end. If we were talking about a promise polyfill for example that would be a different matter.But in the end everyone codes differently. So whatever suits your coding style then use it.
Great article!
It's worth noting that the first 2 examples can be written ever so slightly shorter using
Array.from
as theArray.from
method supports a mapping function as it's second argument.Here's the first example using
Array.from
:And the second example:
You're right! This way is slightly shorter! I'll replace mine with them
Thank you mate!
Here is what I use
Array from for the win I had an issue with array fill hahaha
How Array.fill can break arrays!
Médéric Burlet ・ Oct 7 '20 ・ 2 min read
In the case of no. 5: I would always chose readability over bitwise trickery, when not absolutely necessary. So instead of bitwise AND, just use modulo;
Hey just a small improvement to N something ago example to show/hide plural.
This will not work for months with 31 days.
It's a just simple version for that formatter. That's why it shows average time.
But it's okay with 31 days. If it's more than 30 days then 1 month;
example
You can also replace
Date.now()
with your own date to check withdate.getTime()
Thanks for your work.
Array.from() is amazing! I always used new Array(10). Thanks :)
Great article :D