Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

118
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda