Member-only story
5 Cool Modern JavaScript Features Most Developers Don’t Know
Write less and do more with JavaScript

With JavaScript, you can do one thing in many different ways. Also, JavaScript is evolving with the release of every new ECMAScript specification, adding new useful methods and operators to make the code shorter, and somewhere more readable.
After offering ten JavaScript tricks, I’ve decided to share five more tricks that you can do with JavaScript.
1. Object.entries
Most developers use Object.keys
method to iterate over an object. This method only returns an array of the object keys, not values. We can use Object.entries
to get both key and value.
const person = {
name: 'John',
age: 20
};Object.keys(person); // ['name', 'age']
Object.entries(data); // [['name', 'John'], ['age', 20]]
And to iterate over an object we can do the following:
Object.keys(person).forEach((key) => {
console.log(`${key} is ${person[key]}`);
});// using entries to get key and value both
Object.entries(person).forEach(([key, value]) => {
console.log(`${key} is ${value}`);
});// expected output:
// name is John
// age is 20
Both approaches above return the same result but Object.entries makes it easy to get key-value pair.
2. String replaceAll Method
In JavaScript, to replace all occurrences of a string with another string, we need to use a Regular Expression like the following:
const str = 'Red-Green-Blue';// replaces the first occurrence only
str.replace('-', ' '); // Red Green-Blue// use RegEx to replace all occurrences
str.replace(/\-/g, ' '); // Red Green Blue
But in ES12, a new method is added to String.prototype
named replaceAll
which replaces all occurrences of a string with another string value.
str.replaceAll('-', ' '); // Red Green Blue
3. Numeric Separator
You can use an underscore _
as a numeric separator, which makes it easy to count the…