There are a lot of great one-liners in here that can be very useful, but we may need to be more careful with array shuffling. For some purposes a simple random shuffle will suffice, but most shuffles have bias in them, and the amount of bias can depend on the JavaScript engine.
👨💻 Professional problem solver - 🎧 Music lover Hello! Thanks for checking out my profile. If you haven't yet, make sure to also follow me on my other social media! ⬇️
From my perspective one-liners are ok as long as they are readable. Nowadays there are a lot of bundlers, compilers etc. which are able to make it more compact so we don't write code for making computer happy. We do it for other developers who need to spend time to understand it.
One good advice: Be pro instead of look like a pro.
Hi there! I'm a passionate UI/UX Developer hailing from India with 3+ years of enriching experience. I love crafting digital experiences that blend aesthetics with functionality.
I agree that we must keep attention that "one line code" cant suffice. For me a good/pro code portion is a code easy to read/understand/adopt/maintain/extend. Lenght of the code could be a way de improve the adoption but for ex. a var name or method name or statement complexity of a block.. are impotant too. If a junior is able to quickly adopt and extend your code. Then you're a pro 😎 Thanks for this great article 👌
I'm a friendly, non-dev, cisgender guy from NC who enjoys playing music/making noise, hiking, eating veggies, and hanging out with my best friend/wife + our 3 kitties + 1 greyhound.
How’s it going, I'm a Adam, a Full-Stack Engineer, actively searching for work. I'm all about JavaScript. And Frontend but don't let that fool you - I've also got some serious Backend skills.
Location
City of Bath, UK 🇬🇧
Education
11 plus years* active enterprise development experience and a Fine art degree 🎨
There should be a disclaimer that wanting to look like a pro is not being a pro. Writing these and explaining the benefits and drawbacks is being a pro
I am a senior software Developer@Hexagon, an enthusiastic full-stack developer, and professionally a web development engineer with 2+ years of experience in React and a huge fan of SPAs.
There are a lot of great one-liners in here that can be very useful, but we may need to be more careful with array shuffling. For some purposes a simple random shuffle will suffice, but most shuffles have bias in them, and the amount of bias can depend on the JavaScript engine.
The Fisher-Yates shuffle is reliable and unbiased.
For a good visualization of differences, take a look at Mike Bostock's page Will It Shuffle? and try it in different browsers to see the variation.
That's true I considered including the bias, however I thought it might confuse people more.
The Fisher-Yates algorithm is great!
Remember that one-liners are not always better/faster/easier.
Readability goes over being clever.
Especially when a one-liner only passes its parameters to another method like this one
What's wrong with just:
If anything, the
copyToClipboard
should check if the clipboard API is available to use.A guide to writing clean and readable code
Mr. Linxed ・ Feb 23
Hex to rgb can be one-lined too (not sure why you include the alpha channel if you're not doing anything to it though...):
From my perspective one-liners are ok as long as they are readable. Nowadays there are a lot of bundlers, compilers etc. which are able to make it more compact so we don't write code for making computer happy. We do it for other developers who need to spend time to understand it.
One good advice: Be pro instead of look like a pro.
We love one liners but it can be challenging and sometimes confusing, especially for junior developers.
Btw, thanks for sharing this. Keep posting ❤️👍
I agree that we must keep attention that "one line code" cant suffice. For me a good/pro code portion is a code easy to read/understand/adopt/maintain/extend.
Lenght of the code could be a way de improve the adoption but for ex. a var name or method name or statement complexity of a block.. are impotant too. If a junior is able to quickly adopt and extend your code. Then you're a pro 😎
Thanks for this great article 👌
Thanks Brice!
Thank you!
Just have to say that I'm really digging this cover image. It reminds me of synthwave music!
Thanks Michael! It was definitely inspired.
There should be a disclaimer that wanting to look like a pro is not being a pro. Writing these and explaining the benefits and drawbacks is being a pro
Great post!
Thank you!
Very useful!
Thanks!
Javascript is great
I use this one-liner often when a dataset contains duplicates, comes in handy:
(array) => [...new Set(array)]
I love that!
Nice, but that one is even better:
Title: Top 20 JavaScript One-Liners That Don't Actually Work
𒎏Wii 🏳️⚧️ ・ Feb 15
To capitalize first letter of each word in a string.

Thanks for the contribution Gajanan!