In this Article we will go through how to check if a value is a 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 isNumber = value => !isNaN(parseFloat(value)) && isFinite(value);
In this Article we will go through how to check if a value is a plain 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 isPlainObject = v => (!!v && typeof v === 'object' && (v.__proto__ === null || v.__proto__ === Object.prototype));
In this Article we will go through how to check if a value is a regular expression 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 isRegExp = value => Object.prototype.toString.call(value) === '[object RegExp]';
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);
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);
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);
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();
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);
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);
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);