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

119
Views
Javascript if function makes other code not run

I have an if function that checks if the link doesn't break the rules:

const file = data.file.toLowerCase()
if(!file.startsWith('https://')
    || !file.endsWith('.gif')
    || !file.endsWith('.png')
    || !file.endsWith('.jpg')
    || !file.endsWith('mp4')
    || !file.endsWith('mp3')
    || !file.endsWith('.webm')
)
    return

This makes other code not run, even if the link doesn't break the rules. Can anyone help?

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

0

!file.endsWith('.gif') || !file.endsWith('.png') ...

This will always return true as a string can end with .gif (which matches !file.endsWith('.png') ), .png (which matches !file.endsWith('.gif')), or other things that will match both. Therefore the return will always run.

You may instead need &&

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!