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?! 😮

WAT.
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.

Subscribe to Vaidehi Joshi

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!