MTGZone
  • Communities
  • Create Post
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
☆ Yσɠƚԋσʂ ☆@lemmy.ml to Programmer Humor@lemmy.mlEnglish · 1 month ago

JavaScript

lemmy.ml

message-square
8
fedilink
  • cross-posted to:
  • programmer_humor@programming.dev
1

JavaScript

lemmy.ml

☆ Yσɠƚԋσʂ ☆@lemmy.ml to Programmer Humor@lemmy.mlEnglish · 1 month ago
message-square
8
fedilink
  • cross-posted to:
  • programmer_humor@programming.dev
alert-triangle
You must log in or register to comment.
  • CommanderCloon@lemmy.ml
    link
    fedilink
    arrow-up
    1
    ·
    1 month ago

    That’s easily explained by + being the concatenation operator though. Those are two different operations with the same symbol

    Just use typescript anyway lol

  • propter_hog [any, any]@hexbear.net
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 month ago

    + is overloaded for string concatenation, but - isn’t so the interpreter coerces the “11” into a number first.

    • ☆ Yσɠƚԋσʂ ☆@lemmy.mlOP
      link
      fedilink
      arrow-up
      1
      ·
      1 month ago

      yup

  • HiddenLayer555@lemmy.ml
    link
    fedilink
    English
    arrow-up
    1
    ·
    edit-2
    1 month ago
    ('b' + 'a' + + 'a' + 'a').toLowerCase()
    

    Returns “banana”

    • doubtingtammy@lemmy.ml
      link
      fedilink
      arrow-up
      1
      ·
      1 month ago

      wut

      • propter_hog [any, any]@hexbear.net
        link
        fedilink
        English
        arrow-up
        1
        ·
        edit-2
        1 month 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”.

        • sgh@lemmy.ml
          link
          fedilink
          arrow-up
          1
          ·
          1 month ago

          The space makes that two different tokens, in reality what happens is ‘a’ + (+‘a’) that resolves to ‘a’ + ‘NaN’.

          • propter_hog [any, any]@hexbear.net
            link
            fedilink
            English
            arrow-up
            1
            ·
            30 days ago

            Yep, I believe you’re right

Programmer Humor@lemmy.ml

programmerhumor@lemmy.ml

Subscribe from Remote Instance

Create a post
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: !programmerhumor@lemmy.ml

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.
Visibility: Public
globe

This community can be federated to other instances and be posted/commented in by their users.

  • 556 users / day
  • 1.33K users / week
  • 0 users / month
  • 1.63K users / 6 months
  • 1 local subscriber
  • 37K subscribers
  • 114 Posts
  • 270 Comments
  • Modlog
  • mods:
  • cat_programmer@lemmy.ml
  • BE: 0.19.5
  • Modlog
  • Legal
  • Instances
  • Docs
  • Code
  • join-lemmy.org