, 15 tweets, 3 min read Read on Twitter
In today's edition of "oh my god everything is so freaking interconnected", I learned a W I L D thing about JavaScript's parseInt function:
You're probably already be familiar with how parseInt() works; it converts a string into an integer, based on the radix/base you pass to it.
For example:

parseInt("150.00", 10)
=> 150

Pretty straightforward, right?
So what happens when you try to parseInt() something that's not a number? It ought to return NaN, as it's not a number. Except LOOK at this:
When you parseInt() with the string argument "null" and a radix of 24, it returns...a number?! 😮

If you remember your number systems, you know that in hexadecimals, after you get to 9, you start adding letters as digits: A, B, C, D, E, F
Guess what? In base 24, the letter "n" just so happens to have a value, LOL. The "n" in "null" is recognized/converted as a numerical value!
Here's the math: in base 24, 0-9 are the first 10 digits. Then come the letters. And since "n" is the 14th letter, it has a value in base 24
Since "n" can be interpreted, it moves on to the next letter: "u". But "u" doesn't have a value in base 24, since there are only 24 digits!
So, the parseInt function just returns the integer value for what "n" represents in base 24 → 23.

Wild, right?! And also kind of amazing.
Based on this logic, I bet you could figure out which base you'd need to use in order to convert the ENTIRE "null" string into an integer.
Since "u" is the 21st letter of the alphabet and there are 10 digits (0-9) before the letters, the first radix we can covert at is: base 31!
Moral of the story: you never know when the fundamentals will come in handy! Learning about bases for #basecs made this easy for me to see.
The other moral is lol, javascript ¯\_(ツ)_/¯
PS this is what happens whenever @wycats shows me something that blows my mind—I spent 30 minutes in my JS console trying to understand it 😂
Missing some Tweet in this thread?
You can try to force a refresh.

Like this thread? Get email updates or save it to PDF!

Subscribe to Vaidehi Joshi
Profile picture

Get real-time email alerts when new unrolls are available from this author!

This content may be removed anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Did Thread Reader help you today?

Support us! We are indie developers!

This site is made by just three indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member and get exclusive features!

Premium member ($3.00/month or $30.00/year)

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!