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

In this Article we will go through how to check if a string contains lower 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 containsLowerCase = str => str !== str.toUpperCase();

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

In this Article we will go through how to check if a string contains only ascii 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 isAscii = str => /^[\x00-\x7F]+$/.test(str);

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

In this Article we will go through how to check if a string contains only digits 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 isNumeric = str => !/[^0-9]/.test(str);

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 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;

Sep 9, 2021 JavaScript
How to check if a number is even in JavaScript

In this Article we will go through how to check if a number is even 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 isEven = number => number % 2 === 0;

Sep 9, 2021 JavaScript
How to check if a number is in a given range in JavaScript

In this Article we will go through how to check if a number is in a given range 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 inRange = (num, a, b, threshold = 0) => (Math.min(a, b) - threshold <= num && num <= Math.max(a, b) + threshold);

Sep 9, 2021 JavaScript
How to check if a number is negative in JavaScript

In this Article we will go through how to check if a number is negative 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 isNegative = number => Math.sign(number) === -1;

Sep 9, 2021 JavaScript
How to check if a number is odd in JavaScript

In this Article we will go through how to check if a number is odd 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 isOdd = number => number % 2 !== 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());