Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

160
Views
Dismiss error when variable is undefned javascript

When I run this code

return (
          val.ticket.ticketNumber.toLowerCase().includes(inputText) ||
          val.ticket.source.toLowerCase().includes(inputText) ||
          val.ticket.lagoonMaterial.toLowerCase().includes(inputText) ||
          val.ticket.vendor.toLowerCase().includes(inputText) ||
          val.ticket.gallons.toLowerCase().includes(inputText);
        );

Sometimes one the properties is missing and that gives me this error

TypeError: undefined is not an object (evaluating 'val.ticket.vendor.toLowerCase')

How can I dismiss this property without having to use if statement?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use nullish coalescing operators. It's like an OR (||), but it only works for null and undefined values. The placement of ?? is just like ||

function getValue(num) {
  return num ?? 'Pass a number';
}

console.log(getValue(5));

console.log(getValue());

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!