Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

209
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda