You won't be able to answer this simple JavaScript question!
Sadeedpv🥇

Sadeedpv🥇 @sadeedpv

About: Human being

Location:
Kerala, India
Joined:
Feb 19, 2022

You won't be able to answer this simple JavaScript question!

Publish Date: Aug 16 '23
48 29

Last night, I was scrolling through twitter and I found a interesting JavaScript question, and I bet you won't be able to answer this without cheating.

Let's see how long would would it take for you to answer this one:

What does ("b" + "a" + + "a" + "a").toLowerCase() output in JavaScript?

The question does look simple, but the answer will definitely blow your mind.

Tell me how long it took you to answer in the comments.

And Yes, JavaScript is crazy!

Comments 29 total

  • Dragon
    DragonAug 16, 2023

    JavaScript is really a magical language

  • Bob dnaeil
    Bob dnaeilAug 16, 2023

    Is it bAaa

  • Vladas Saulis
    Vladas SaulisAug 16, 2023

    banana

  • SkyHops
    SkyHopsAug 16, 2023

    "baaa"

    • Sadeedpv🥇
      Sadeedpv🥇Aug 16, 2023

      Its actually banana, basically the unary plus(++) of 'a' gives NaN which gives us 'baNaNa' and convert it to lowercase => banana

      • SkyHops
        SkyHopsAug 16, 2023

        Do you need

        "use strict" 
        
        Enter fullscreen mode Exit fullscreen mode

        at the top of the script 🤔
        I used an online Javascript console.

        • Sadeedpv🥇
          Sadeedpv🥇Aug 16, 2023

          Try this code :

          console.log(("b" + "a" + + "a" + "a").toLowerCase());
          
          Enter fullscreen mode Exit fullscreen mode
          • SkyHops
            SkyHopsAug 16, 2023

            Thank you; my mistake.
            I didn't see the ++.
            For my defence on my phone it red:

            ("b" + "a" +
             + "a" + "a").toLowerCase()
            
            Enter fullscreen mode Exit fullscreen mode
      • chrdek
        chrdekAug 17, 2023

        yep, that' s what it does.

  • Nadir Hussain
    Nadir HussainAug 16, 2023

    banana

  • Joe Burkhart
    Joe BurkhartAug 16, 2023

    It took me a second because I didn't notice the ++ (Unary plus) right away. Definitely got a little laugh out of me once I caught it though.

  • overFlow
    overFlowAug 16, 2023

    now i see why typeScript and them exist.
    obviously it is string :"b"+string :"a"+NaN+string :"a".
    Do not ask me about the last string :"a".
    let us say it is your homework.

  • BOSSHIE
    BOSSHIEAug 17, 2023
    console.log(("b" + "a" + + "a" + "a").toLowerCase());
    
    Enter fullscreen mode Exit fullscreen mode

    banana

  • Khair Alanam
    Khair AlanamAug 18, 2023

    That's honestly cool.

    baNaNa

  • Meir Gabay
    Meir GabayAug 18, 2023

    I wanted to see if ChatGPT will get it right.. And it did :)

    The NaN part is very interesting, as one of the "a" chars is dropped, initially, I didn't understand why it's not "bananaa" (extra "a"), now I get it 💪🏻

    Image description

  • intermundos
    intermundosAug 20, 2023

    In your case it's bananaa

  • Chrissy Vinco
    Chrissy VincoAug 20, 2023

    Okay the person who thought of this problem is soooo clever

  • Alex Lohr
    Alex LohrAug 21, 2023

    NaN is actually part of IEEE 754, which is used in most languages to express floating point numbers.

  • Camilo Martinez
    Camilo MartinezAug 22, 2023

    Now try console.log(new Array(4).join(Number('y tho') + 'a')+' Batman!') 🦇

    • Sadeedpv🥇
      Sadeedpv🥇Aug 22, 2023

      NaNaNaNaNaNa batman! is that the desired output or am I missing something? 🤔

      • Camilo Martinez
        Camilo MartinezAug 22, 2023

        Yes, maybe for people from my generation 😅.

        Now I think this joke is too old 👴

  • codeyStein
    codeySteinSep 8, 2023

    It's the little things that makes javascirpt so annoying :)

Add comment