when I call it with a variable thats null, it returns "Hello, welcome null!"
That means you're not calling it with name set to null, you're calling it with name set to "null" (or an unlikely second possibility I'll cover later). "null" is not equal to null (either == or ===).
Example:
function makeTitleWith(name) {
if (name === null) {
return "Hello, welcome to my app!"
} else {
return "Hello, welcome " + name + "!"
}
}
console.log(makeTitleWith("null"));
// or more likely:
var n = String(null);
console.log(makeTitleWith(n));
You probably want to fix where you're calling it, since that "null" is probably the result of converting null to string.
The unlikely second possibility: You're calling it with name set to an object that, when converted to string, converts to "null", like this:
function makeTitleWith(name) {
if (name === null) {
return "Hello, welcome to my app!"
} else {
return "Hello, welcome " + name + "!"
}
}
var n = {
toString() {
return "null";
}
};
console.log(makeTitleWith(n));
I very much doubt that's what's going on.