Dino Geek, try to help you

What is the difference between undefined and null in JavaScript?


In JavaScript, `undefined` and `null` are both special values signifying “no value” or “no object”. However, they are used in slightly different scenarios.

`undefined` means that a variable has been declared, but has not yet been assigned a value. You might also get `undefined` when trying to access a non-existing object property or array element.

Example:

```
let testVar;
console.log(testVar);
// logs: undefined
console.log(nonexistentVar);
// throws an error
console.log({}[‘prop’]);
// logs: undefined
console.log([]0);
// logs: undefined
```

On the other hand, `null` is an assignment value that represents no value or no object. It implies the absence of a value intentionally and explicitly. It needs to be assigned.

Example:

```
let testVar = null;
console.log(testVar);
// logs: null
```

You can check for `undefined` and `null` through following means:

```
let testVarUndefined;
let testVarNull = null;

console.log(testVarUndefined = undefined); // logs: true console.log(testVarUndefined = null); // logs: false

console.log(testVarNull = null); // logs: true console.log(testVarNull = undefined); // logs: false
```

In non-strict equality `==`, `undefined` and `null` are somewhat interchangeable and equal to each other:

```
console.log(undefined == null); // logs: true
```


Simply generate articles to optimize your SEO
Simply generate articles to optimize your SEO





DinoGeek offers simple articles on complex technologies

Would you like to be quoted in this article? It's very simple, contact us at dino@eiki.fr

CSS | NodeJS | DNS | DMARC | MAPI | NNTP | htaccess | PHP | HTTPS | Drupal | WEB3 | LLM | Wordpress | TLD | Domain name | IMAP | TCP | NFT | MariaDB | FTP | Zigbee | NMAP | SNMP | SEO | E-Mail | LXC | HTTP | MangoDB | SFTP | RAG | SSH | HTML | ChatGPT API | OSPF | JavaScript | Docker | OpenVZ | ChatGPT | VPS | ZIMBRA | SPF | UDP | Joomla | IPV6 | BGP | Django | Reactjs | DKIM | VMWare | RSYNC | Python | TFTP | Webdav | FAAS | Apache | IPV4 | LDAP | POP3 | SMTP

| Whispers of love (API) | Déclaration d'Amour |






Legal Notice / General Conditions of Use