ryan
link
fedilink
81Y

Oh man, you’ve got me itching to get into the intricacies of JavaScript…

One fun example of the difference: when doing arithmetic operations, null is indeed converted to 0, but undefined is converted to NaN. This has to do with null being an assigned value that represents empty, whereas undefined is not actually a value but a response indicating that there was no value assigned in the first place.

@dan@upvote.au
link
fedilink
7
edit-2
1Y

response indicating that there was no value assigned in the first place.

You can explicitly assign undefined to a variable though.

Another fun fact about JavaScript is that undefined never used to be a keyword. If you did var foo = undefined, foo would indeed have a value of undefined, but it was only because there was no variable called undefined in scope!

You could do var undefined = 42 then var foo = undefined would actually set foo to 42! window.undefined = 42 would break all sorts of things.

Thankfully this was fixed with ES5 in 2009, although it took a few years for browsers to make the change.

darcy
link
fedilink
41Y

javascript moment

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