Just spent 20 mins trying to figure out why new lines weren't printing and why random '0's were in the text.

Turns out I was replacing with +"\n" which JavaScript converts to a 0.

Fuck this

  • 2
    Wait what
  • 1
    Haha, Number("\n") == 0. Good to know I guess.

    Edit: wait, I somehow mixed up minus and plus (minus will do implicit number conversion). Can you show the code? I would be interested in inspecting how that happened
  • 1
    @theuser it was litturally string.replace(/\n/g,+"\n"+CONST); and +"\n" is changed to 0.

    I was making a debugging/ testing tool and wanted a make the start of each line nice.
  • 1
    @LavaTheif I just noticed that +'\n' gets converted to 0 but +'a' into NaN

    What the fuck is even happening
  • 1
    That explains why my bot's log function wasn't working properly.
  • 0
    @LavaTheif Ah so you did convert it do a number. I haven't been messing around with newlines before, but just like empty string and whitespace, a newline is perceived as "nothing".

    Number("") == 0
    Number(" ") == 0
    Number("\n") == 0

    Number(null) == 0
    Number(undefined) == NaN
  • 1
    @WildPotato what you mean is *strongly* typed languages. Static typing is entirely different
  • 0
    @pxeger Static vs dynamic, the difference is knowing when you've ballsed it up pretty much.
  • 0
    What?? This is the kind of shit that makes me wish I didn’t know JS and that it would get replaced by something else already
Add Comment