DEV Community

Discussion on: New ES2019 JavaScript features every developer should be excited about

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. 👍