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

200
Views
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 answers
Answer question

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 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!