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

In this Article we will go through how to check if an object is empty 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 isEmpty = obj => Reflect.ownKeys(obj).length === 0 && obj.constructor === Object;

Sep 9, 2021 JavaScript
How to validate a gregorian date in JavaScript

In this Article we will go through how to validate a gregorian date 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 isValidDate = (m, d, y) => 0 <= m && m <= 11 && 0 < y && y < 32768 && 0 < d && d <= (new Date(y, m, 0)).getDate();

Sep 9, 2021 JavaScript
How to check if a string contains only letters and numbers in JavaScript

In this Article we will go through how to check if a string contains only letters and numbers 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 isAlphanumeric = str => /^[0-9A-Z]+$/i.test(str);

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

In this Article we will go through how to check if a string contains only letters 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 isAlpha = str => /^[A-Z]+$/i.test(str);

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

In this Article we will go through how to check if a string contains upper case characters 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 containsUpperCase = str => str !== str.toLowerCase();

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 hexadecimal number in JavaScript

In this Article we will go through how to check if a string is a hexadecimal number 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 isHexadecimal = str => /^[A-F0-9]+$/i.test(str);

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 an octal number in JavaScript

In this Article we will go through how to check if a string is an octal number 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 isOctal = str => /^(0o)?[0-7]+$/i.test(str);