Oh EcmaScript what’s new?

Last month, June, the newest version of EcmaScript was officially released. The feeling of looking at the latest updates included in ES8 is somewhat similar to opening presents on a Christmas morning as a youth. Thinking “what is included and available now” and “what do I have to hope for next year”. This grabs the attention of a rather large audience of JS engineers every year. For those who have allowed this release to slip under their radar I’ll quickly overview some interesting changes. If you are all of a sudden very interested in the entirety of the included changes you can find them here.

The first update we’ll be touching of that has been officially included in ES8 is a method that has been experimental for quite some time.

Object.values(obj)

Above is the declaration of the function. Object.values returns an array of the passed object’s values in the same order that a for in loop would feed back. Essentially the values version of the already existing Object.keys.

const obj = { a: 'I am a value', b: Infinity};
Object.values(obj); // -> ['I am a value', Infinity]

Another cool method included in the update is Object.entries, which returns an array whose values are the key value pairs of the passed object in an array.

const obj = { a: 'I am a value', b: Infinity};
Object.entries(obj); // -> [['a', 'I am a value'], ['b', Infinity]]

The next update to cover is including ability to pass trailing commas to function parameter and function arguments without throwing a syntax error. Not a feature that I personally desired, but can understand the appreciation of. This is inspired by the practice of including trailing commas Arrays and Objects.

function makeMeRich(author, amount,) {
// Magical stuff
}
makeMeRich(Taijon, Infinity,);

The last update we’ll be covering in this post is String padding. You will see the function declarations below. As you’ll notice you can pass a second argument to the string padding functions “padString” this will act as a place holder until the target length is reached. Examples of this will also be found below.

string.padStart(targetLength [, padString])
string.padEnd(targetLength [, padString])
'trob'.padStart(3);          // 'trob'
'trob'.padStart(6); // ' trob'
'trob'.padStart(7, 'hook'); // 'wootrob'
'trob'.padStart(15, 'now'); // 'nownownownotrob'
'trob'.padStart(8, '88'); // '88trob'
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.