Lemmy.one
  • Communities
  • Create Post
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
☆ Yσɠƚԋσʂ ☆@lemmy.ml to Programmer Humor@lemmy.mlEnglish · 8 个月前

JavaScript

lemmy.ml

message-square
26
fedilink
  • cross-posted to:
  • programmer_humor@programming.dev
173

JavaScript

lemmy.ml

☆ Yσɠƚԋσʂ ☆@lemmy.ml to Programmer Humor@lemmy.mlEnglish · 8 个月前
message-square
26
fedilink
  • cross-posted to:
  • programmer_humor@programming.dev
  • HiddenLayer555@lemmy.ml
    link
    fedilink
    English
    arrow-up
    21
    ·
    edit-2
    8 个月前
    ('b' + 'a' + + 'a' + 'a').toLowerCase()
    

    Returns “banana”

    • doubtingtammy@lemmy.ml
      link
      fedilink
      arrow-up
      9
      ·
      8 个月前

      wut

      • somedev@aussie.zone
        link
        fedilink
        arrow-up
        8
        ·
        8 个月前

        I’m guessing the + + in the middle returns NaN

        • Victoria@lemmy.blahaj.zone
          link
          fedilink
          English
          arrow-up
          4
          ·
          8 个月前

          Indeed, the unary plus operator tries to convert whatever is after it to a number if it isn’t already. Since ‘a’ is not a valid number, it returns NaN (not a number)

      • propter_hog [any, any]@hexbear.net
        link
        fedilink
        English
        arrow-up
        6
        ·
        edit-2
        8 个月前

        ‘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
          8
          ·
          8 个月前

          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
            3
            ·
            8 个月前

            Yep, I believe you’re right

        • Simon 𐕣he 🪨 Johnson@lemmy.ml
          link
          fedilink
          arrow-up
          4
          ·
          edit-2
          8 个月前

          Ironically 'a'++ works in C/C++ because 'a' is char where in JS ‘a’ is string.

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.

  • 17 users / day
  • 726 users / week
  • 1.27K users / month
  • 5.86K users / 6 months
  • 440 local subscribers
  • 40.9K subscribers
  • 1.98K Posts
  • 40.4K Comments
  • Modlog
  • mods:
  • AgreeableLandscape@lemmy.ml
  • cat_programmer@lemmy.ml
  • BE: 0.19.7
  • Modlog
  • Legal
  • Instances
  • Docs
  • Code
  • join-lemmy.org