DEV Community

Cover image for New ES2019 JavaScript features every developer should be excited about

New ES2019 JavaScript features every developer should be excited about

Brian Neville-O'Neill on September 26, 2019

Written by Gbolahan Olagunju✏️ JavaScript has come a long way since its early days, with many new additions and features designed specifically to ...
Collapse
 
thealiilman profile image
Ali Ilman

Optional chaining is something I'm so delighted to see.
All of us have written obj.property && obj.property.anotherProperty, and it's a pain to the eyes when the properties are long.

Collapse
 
victorcorcos profile image
Victor Cordeiro Costa

I hate to be that guy, but I need to nitpick some details of this article. My intention is just to help!

This section...

  • String.trimStart and String.trimEn

should be this

  • String.trimStart and String.trimEnd

Am I right?

And regarding the Optional catch binding, is the structure of both codes really similar?

Take a look at the below code, the console.log() line will only be executed if the try block fail

try {
  const parsedJsonData = JSON.parse(obj);
} catch (error) {
  //the variable error has to be declared weather used or unused
  console.log(obj);
}

Now, take a look at the below code, which have the optional catch binding ... the console.log() will be executed whether the try block fails or not. Not only when it fail, like the previous version.

function getName () {
  let name = "Gbolahan Olagunju";
  try {
    name = obj.details.name
  } catch {}
  console.log(name);
}

I am thinking here... maybe the similar structure will be something like this...

function getName () {
  let name = "Gbolahan Olagunju";
  try {
    name = obj.details.name
  } catch {
    console.log(name);
  }
}

Am I right?

Thanks!

Great article, I personally love the optional chaining operator ?., this makes the code so much more readable. However, it is good to mention that we need to avoid calling it when it it is not necessary, otherwise we can have unnecessary performance issues and unclear code behaviors. 👍

Collapse
 
tclain profile image
Timothée Clain

pipeline operator !! yay

Collapse
 
anshap1719 profile image
Anshul Sanghi

Wow, I am working on a project right now that could literally use all of these features on an extensive level. I’ve found ts-optichain for optional chaining very good for now but the rest, I would really love to see. Is there a way to use these features with babel maybe?

Collapse
 
samanocedillo profile image
Samano Cedillo

Buen post!

Gracias por el aporte.

Collapse
 
danielo515 profile image
Daniel Rodríguez Rivero

Is this real life? or is just fanta-sea?
By the way, I don't see why would we need to add an empty catch block, it will be better to make it entirely optional.

Collapse
 
mateiadrielrafael profile image
Matei Adriel

U should open a proposal or something, amazing idea

Collapse
 
gwigwam profile image
GWigWam

Hey, small detail:

In the code for trimStart/trimEnd you misspell 'massage'. Also, the output of message.trimEnd(); would still have the spaces at the start (left) of the string right?

Collapse
 
giancorzo profile image
Giancarlo Corzo

Nice article. Just a little bug. A quote is missing in the function sayName() console.log

Collapse
 
zooly profile image
Hugo Torzuoli

Indeed missing backtick at the start of the log

Collapse
 
manuelojeda profile image
Manuel Ojeda

Nested chaining 👌

Collapse
 
evolutionxbox profile image
Jonathan Cousins

Hasn’t ECMAScript 2019 already been released?

Collapse
 
mogery profile image
Gergő Móricz

WOOT FOR OPTIONAL CHAINING!

Collapse
 
nestordgs profile image
Nestor Gutiérrez

Can't wait to see Optional Chaining