In this Article we will go through how to get the first defined and non null argument 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 coalesce = (...args) => args.find(item => item !== undefined && item !== null);
In this Article we will go through how to get the value of a cookie 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 cookie = name => `; ${document.cookie}`.split(`; ${name}=`).pop().split(';').shift();
In this Article we will go through how to get the value of a param 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 getParam = (url, param) => new URLSearchParams(new URL(url).search).get(param);
In this Article we will go through how to get type of a variable in 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 getTypeOf = obj => Object.prototype.toString.call(obj).match(/\[object (.*)\]/)[1];
In this Article we will go through how to convert 3 digits color to 6 digits 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 toFullHexColor = color => `#${(color.startsWith('#') ? color.slice(1) : color).split('').map(c => `${c}${c}`).join('')}`;
In this Article we will go through how to convert celsius to fahrenheit 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 celsiusToFahrenheit = celsius => celsius * 9/5 + 32;
In this Article we will go through how to convert cookie to 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 cookies = document.cookie.split(';').map(item => item.split('=')).reduce((acc, [k, v]) => (acc[k.trim().replace('"', '')] = v) && acc, {});
In this Article we will go through how to convert fahrenheit to celsius 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 fahrenheitToCelsius = fahrenheit => (fahrenheit - 32) * 5/9;
In this Article we will go through how to convert hex to rgb 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 hexToRgb = hex => hex.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i, (_, r, g, b) => `#${r}${r}${g}${g}${b}${b}`).substring(1).match(/.{2}/g).map(x => parseInt(x, 16));
In this Article we will go through how to convert rgb color to hex 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 rgbToHex = (red, green, blue) => `#${((1 << 24) + (red << 16) + (green << 8) + blue).toString(16).slice(1)}`;