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));
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.
function test() {
return window.location.hostname === 'news.google.com'
}
console.log(test());
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)