1

My node version 12 does not recognize optional chaining operator. Sometimes the match is null. It complains about

Unexpected token '.'

export function getDiscount(description) {
  return description.match(/\d+(\%|\s\bpercent\b)/)?.[0];
}

Do I need to set an flag or something?

It works here

console.log(null?.[0])
Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
bill.gates
  • 14,145
  • 3
  • 19
  • 47

0 Answers0