propter_hog [any, any]

Post hog

  • 0 Posts
  • 86 Comments
Joined 1 year ago
cake
Cake day: July 3rd, 2024

help-circle












  • propter_hog [any, any]@hexbear.nettoProgrammer Humor@lemmy.mlJavaScript
    link
    fedilink
    English
    arrow-up
    5
    arrow-down
    3
    ·
    edit-2
    26 days ago

    ‘a’ + +

    This part is the same as writing 'a'++ and that returns “NaN” (short for “not a number”) since you can’t increment a character, but this return type is a string, so the interpreter just concatenates it with the other letters: baNaNa. Then that string is converted to lower case to give the final result, “banana”.


  • Precisely. This exact situation from the comic would happen in Java, too, except it complains when you subtract an int from a string. JavaScript was merely designed to minimize errors (since a web browser takes the place of the compiler, and random strangers visiting your site shouldn’t get interpretation errors) so instead of throwing up it just does its best at interpreting what you meant.