this post was submitted on 06 Jul 2023
537 points (97.4% liked)

Programmer Humor

19551 readers
995 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] fart@sh.itjust.works 12 points 1 year ago (3 children)

not sure the distinction between null and undefined is doing anything for me here

[–] JackbyDev@programming.dev 8 points 1 year ago

Basically JavaScript uses undefined to mean keys that don't exist. You know how sometimes when you're wondering about the semantics of "present but null" and "absent"? It's basically that. Undefined means it isn't there but things are only null if they've been set to null.

There are probably more nuances but that is the gist.

[–] deegeese@sopuli.xyz 6 points 1 year ago

One is missing but has expected values, the other is completely unknown, like an unimplemented function.

[–] ipkpjersi@lemmy.one 3 points 1 year ago (1 children)

Depends on the programming language. In JavaScript, it literally means that like the key or variable does not actually exist. Whereas like in C/C++, writing random bytes to random memory addresses would result in "undefined behaviour" which means basically anything could happen.

[–] crystal@feddit.de 2 points 1 year ago* (last edited 1 year ago)

In Javascript you can do let a = undefined, defining the variale a as undefined.

A significant difference to defining it as null is that typeof null == "object", while typeof undefined == "undefined".