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

201
Visualizações
Check if subdomain is true or false? javascript

Newbie here and I've been trying to write a function that checks if a subdomain is true or false

any guidance is appreciated! and sorry if it's really basic

function test(t) {
  if (window.location.hostname === 'news.google.com') {
    return true;
  }
  return t;
}
let x;
console.log(test(x));
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

So there are 2 ways you could go about this. From your example code we can remove the parameter as it isn't used, t in your example is always undefined. We can also just return the result of the equality operator since it will return true / false.

  1. If you want to have a static check i.e. always check for the same domain name
function test() {
  return window.location.hostname === 'news.google.com'
}
console.log(test());
  1. If you want to allow the domain name to change
function test(domain) {
  return window.location.hostname === domain
}
console.log(test('news.google.com'));

Note:

Naming functions is a very important concept so you might want to think of a name that better represents the operation taking place such as isDomainEqualTo(domain)

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