Sep 9, 2021 JavaScript
How to check if a string contains whitespace in JavaScript

In this Article we will go through how to check if a string contains whitespace only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.

Let's define this short function:

const containsWhitespace = str => str => /\s/.test(str);

Sep 9, 2021 JavaScript
How to check if a string is a hexadecimal color in JavaScript

In this Article we will go through how to check if a string is a hexadecimal color only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.

Let's define this short function:

const isHexColor = color => /^#([0-9A-F]{3}|[0-9A-F]{4}|[0-9A-F]{6}|[0-9A-F]{8})$/i.test(color);

Sep 9, 2021 JavaScript
How to check if a string is a mongodb objectid in JavaScript

In this Article we will go through how to check if a string is a mongodb objectid only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.

Let's define this short function:

const isMongoId = str => str.length === 24 && /^[A-F0-9]+$/i.test(str);

Sep 9, 2021 JavaScript
How to check if a string is upper case in JavaScript

In this Article we will go through how to check if a string is upper case only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.

Let's define this short function:

const isUpperCase = str => str === str.toUpperCase();

Sep 9, 2021 JavaScript
How to check if a value is an object in JavaScript

In this Article we will go through how to check if a value is an object only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.

Let's define this short function:

const isObject = v => (v !== null && typeof v === 'object');

Sep 9, 2021 JavaScript
How to check if a value is nil in JavaScript

In this Article we will go through how to check if a value is nil only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.

Let's define this short function:

const isNil = (value) => value == null;

Sep 9, 2021 JavaScript
How to check if a date is a weekday in JavaScript

In this Article we will go through how to check if a date is a weekday only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.

Let's define this short function:

const isWeekday = (date = new Date()) => date.getDay() % 6 !== 0;

Sep 9, 2021 JavaScript
How to check if a date is between two dates in JavaScript

In this Article we will go through how to check if a date is between two dates only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.

Let's define this short function:

const isBetween = (date, min, max) => (date.getTime() >= min.getTime() && date.getTime() <= max.getTime());

Sep 9, 2021 JavaScript
How to check if a date occurs in the current year in JavaScript

In this Article we will go through how to check if a date occurs in the current year only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.

Let's define this short function:

const isCurrentYear = (date) => date.getUTCFullYear() === new Date().getUTCFullYear();

Sep 9, 2021 JavaScript
How to check if a number is a power of 2 in JavaScript

In this Article we will go through how to check if a number is a power of 2 only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.

Let's define this short function:

const isPowerOfTwo = number => (number & (number - 1)) === 0;