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 number is positive in JavaScript

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

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 get the file name from a url in JavaScript

In this Article we will go through how to get the file name from a url 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 fileName = url => url.substring(url.lastIndexOf('/') + 1);

Sep 9, 2021 JavaScript
How to get the length of a string in bytes in JavaScript

In this Article we will go through how to get the length of a string in bytes 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 bytes = str => new Blob([str]).size;

Sep 9, 2021 JavaScript
How to get the number of a character in a string in JavaScript

In this Article we will go through how to get the number of a character in a string 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 characterCount = (str, char) => str.split(char).length - 1;

Sep 9, 2021 JavaScript
How to make the first character of a string lowercase in JavaScript

In this Article we will go through how to make the first character of a string lowercase 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 lowercaseFirst = str => `${str.charAt(0).toLowerCase()}${str.slice(1)}`;