Sep 9, 2021 JavaScript
How to get the yesterday date in JavaScript

In this Article we will go through how to get the yesterday 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 yesterday = (d => new Date(d.setDate(d.getDate() - 1)))(new Date);

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 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 value is a business identifier code in JavaScript

In this Article we will go through how to check if a value is a business identifier code 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 isBIC = value => /^[a-zA-Z]{6}[a-zA-Z0-9]{2}([a-zA-Z0-9]{3})?$/.test(value);

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

In this Article we will go through how to check if a value is 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 isString = value => Object.prototype.toString.call(value) === '[object String]';

Sep 9, 2021 JavaScript
How to add am pm suffix to an hour in JavaScript

In this Article we will go through how to add am pm suffix to an hour 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 suffixAmPm = h => `${h % 12 === 0 ? 12 : h % 12}${h < 12 ? 'am' : 'pm'}`;

Sep 9, 2021 JavaScript
How to calculate the number of difference days between two dates in JavaScript

In this Article we will go through how to calculate the number of difference days 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 diffDays = (date, otherDate) => Math.ceil(Math.abs(date - otherDate) / (1000 * 60 * 60 * 24));

Sep 9, 2021 JavaScript
How to convert a date to yyyy-mm-dd format in JavaScript

In this Article we will go through how to convert a date to yyyy-mm-dd format 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 formatYmd = date => date.toISOString().slice(0, 10);

Sep 9, 2021 JavaScript
How to format a date for the given locale in JavaScript

In this Article we will go through how to format a date for the given locale 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 format = (date, locale) => new Intl.DateTimeFormat(locale).format(date);