13 JavaScript One-Liners That’ll Make You Look Like a Pro

In just a few minutes, step up your JS knowledge.

Twan Mulder
DailyJS

--

Photo by CHUTTERSNAP on Unsplash

JavaScript can do a lot of amazing things!

From complex frameworks to handling API’s, there is just SO much to learn.

But, it also enables you to do some awesome stuff using just one single line.

Check out these 13 JavaScript One-Liners That’ll Make You Look Like a Pro!

1. Get a random boolean (true/false)

This function will return a boolean (true or false) using the Math.random() method. Math.random will create a random number between 0 and 1, after which we check if it is higher or lower than 0.5. That means it’s a 50%/50% chance to get either true or false.

JS code block showing how to use the Math Random method to get a random boolean value.
const randomBoolean = () => Math.random() >= 0.5;console.log(randomBoolean());
// Result: a 50/50 change on returning true of false

2. Check if the provided day is a weekday

Using this method, you’ll be able to check if the date that you provide in the function is…

--

--

Twan Mulder
DailyJS

Frontend Developer who loves creating enticing experiences | Employed at De Bijenkorf