How to determine if a variable is undefined or null in JavaScript?
Hello everyone! I just started learning JavaScript and encountered this problem. In my code, I often need to check whether a variable exists or not, but I get confused between `undefined` and `null`.
For example, I have a function that takes a parameter `name`. If the user didn't pass a name, I want to display the message "Name not specified". But if they passed `null`, I also want to handle that as the absence of a name.
Here's what I tried:
```javascript
function greet(name) {
if (name == undefined) {
console.log("Name not specified");
} else {
console.log("Hello, " + name);
}
}
greet(); // outputs "Name not specified" — works
greet(null); // outputs "Hello, null" — but should output "Name not specified"!
```
Why doesn't `name == undefined` catch `null`? I read that there is an op