JS Quirks – Part-1
Fun with Javascript
JS is a phunny language
Some of us will relate this sentence to the Amitabh Bachchan starrer Namak Haram, but one cannot deny the impact JavaScript has on the evolution of websites, who would like to go back to the 90’s blinky pages that took forever to load and could do no more than navigate from one page to other.
JS evolved and thankfully became powerful enough to be called the language of the internet, from its initial days of Netscape navigator it is now ubiquitous, so much so we tend to take its presence for granted.
JS currently finds its usage not only in Webpages but almost all areas of programming and application development, Node, AI/ML, Blockchain are the notable modern tech where JS is not left behind and works hand in hand with them.
This blog is about some of the fundamentals of JS which if one is cognizant about will reduce the errors and definitely hours of headache of locating the bug.
This is TIOBE index showing how JS evolved over the years
Programming Language | 2023 | 2018 | 2013 | 2008 | 2003 | 1998 | 1993 | 1988 |
---|---|---|---|---|---|---|---|---|
Python | 1 | 4 | 8 | 7 | 13 | 25 | 20 | – |
C | 2 | 2 | 1 | 2 | 2 | 1 | 1 | 1 |
Java | 3 | 1 | 2 | 1 | 1 | 17 | – | – |
C++ | 4 | 3 | 4 | 4 | 3 | 2 | 2 | 6 |
C# | 5 | 5 | 5 | 8 | 10 | – | – | – |
Visual Basic | 6 | 15 | – | – | – | – | – | – |
JavaScript | 7 | 7 | 11 | 9 | 8 | 22 | – | – |
SQL | 8 | 251 | – | – | 7 | – | – | – |
Assembly language | 9 | 12 | – | – | – | – | – | – |
PHP | 10 | 8 | 6 | 5 | 6 | – | – | – |
Objective-C | 18 | 18 | 3 | 45 | 51 | – | – | – |
Ada | 27 | 30 | 17 | 18 | 15 | 7 | 6 | 2 |
Lisp | 29 | 31 | 12 | 16 | 14 | 6 | 4 | 3 |
Pascal | 198 | 143 | 15 | 19 | 99 | 12 | 3 | 14 |
(Visual) Basic | – | – | 7 | 3 | 5 | 3 | 9 | 5 |
Do you know some infinities are greater than other infinities?
To understand this incredible concept, watch this video https://youtu.be/OxGsU8oIWjY
function run() {
console.log (Math.min() > Math.max()); //--> true
console.log (Math.min() < Math.max()); //--> false
}
run();
Surprise? Well, the first thing to understand is Math.max() is not same as Number.MAX_VALUE, Math.min() and Math.max() can be used to find the lowest or highest value in a list of arguments but if no arguments are provided than Math.min() = Infinity and Math.max() = -Infinity
function run() {
console.log(Math.min()); //-> Infinity
console.log(Math.max()); //-> -Infinity
}
run();
Let’s guess what happens when NaN is provided as an argument
function run() {
console.log(Math.min(0, NaN)); //-> NaN
console.log(Math.max(0, NaN)); //-> -NaN
}
run();
Image source https://www.freecodecamp.org/news/explaining-the-best-javascript-meme-i-have-ever-seen/
Until next time, that’s all Folks!!