10 JavaScript One-liners You Have Got to Add Your Arsenal as a Developer

Step Up your JavaScript game in just a couple of minutes

Twan Mulder
DailyJS

--

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 10 one-liners to step up your JavaScript game!

1. Capitalize the first letter of a string

Using this function, you’ll be able to capitalize the first letter of the input of a string. This could be a single word, but also an entire sentence.

JavaScript function that capitalizes the first letter of a sentence.
// Capitalize the first letter of a string
const capitalize = str => `${str.charAt(0).toUpperCase()}${str.slice(1)}`;
capitalize("hello, you are a cool person!");
// Result: "Hello, you are a cool person!"

2. Calculate the number of days between two dates

--

--

Twan Mulder
DailyJS

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