deleted by creator

“Other alternatives” is a pleonasm, “alternatives” suffices.

We should make a linter for Lemmy. That’ll shut me up.

JackbyDev
link
fedilink
English
71Y

This is JavaScript undefined logic specifically where it means the key isn’t present on the object.

Except you can add the key with an undefined value and it may have different behaviors than if the key was really not there.

JackbyDev
link
fedilink
English
11Y

Please add a trigger warning to this in the future, this is too scary

In JS a Boolean has 4 states.
true
false
undefined (where the key is set to undefined)
undefined (where the key doesn’t exist on the object)

if (obj.value === true) {  
    console.log(1);
} else if (obj.value === false) {
    console.log(2);
} else if ("value" in obj) { // key "value" is in the obj, but it is set to undefined 
    console.log(3);
} else { // key "value" is not in object
    console.log(4);
}

You’re welcome.

deleted by creator

JackbyDev
link
fedilink
English
11Y

Create a post

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

  • Posts must be relevant to programming, programmers, or computer science.
  • No NSFW content.
  • Jokes must be in good taste. No hate speech, bigotry, etc.
  • 1 user online
  • 120 users / day
  • 257 users / week
  • 744 users / month
  • 3.72K users / 6 months
  • 1 subscriber
  • 1.48K Posts
  • 32.6K Comments
  • Modlog