If anyone asks me what programming language they should learn as a beginner, I’ll tell them it’s JavaScript. This powerful language gets involved in almost every aspect of programming — frontend, backend, web app, desktop app, mobile app. The list goes on.

In today’s story, I’ll show you 18 useful JavaScript snippets that I use most of the time. They helped me save time for common development tasks. Let’s get into it.

1. maxItemOfArray

This one return the maximum number from an array.

const maxItemOfArray = (arr) => […arr].sort((a, b) => b — a).slice(0, 1)[0];

let maxItem = maxItemOfArray([3, 5, 12, 5]);

2. areAllEqual

This snippet checks if all the items of a array are equal.

const areAllEqual = array => array.every(item => item === array[0]);

let check1 = areAllEqual([3, 5, 2]); // false
let check2 = allEqual([3, 3, 3]); // true

#javascript #javascript-tips

18 Useful JavaScript Snippets for Common Tasks You Can Use From Today
24.45 GEEK