How to properly check if a variable is undefined in JavaScript?
Hi everyone! I just started learning JavaScript and ran into a problem. I need to check whether a variable is defined or not to avoid errors in my code. I tried different methods, but they behave differently, and I'm confused.
Here's an example of my code:
```javascript
let myVar;
console.log(myVar); // undefined
if (myVar == undefined) {
console.log('Variable is not defined');
}
if (typeof myVar === 'undefined') {
console.log('Also not defined');
}
```
But when I try to check a non-existent variable (one I haven't even declared), I get a ReferenceError. For example:
```javascript
if (someVar === undefined) {
console.log('Won't work');
}
```
Also, when I use `==` and `===` — is there a difference? I've also heard about `void` and that you can compare with