"b" + "a" + +"a" + "a" ? Banana? What ?
JavaScript is one of the most important programming languages in the world. Whether you're a front-end or back-end developer, it's essential to be aware of its quirky—and sometimes funny—behaviors. In this article, I’ll highlight some of these intriguing aspects. Let’s dive in!
Math.min and Math.max
When you try to do something like the snippet code below the return is true. The most interesting point is that the Math.min() returns the special number in Javascript named Infinity, and the Math.max() returns -Infinity.
Not A Number
In JavaScript, 'Not A Number' is abbreviated as NaN. It's a special value used to represent undefined or unrepresentable numerical results. First, it's important to note that NaN is typed as a number in JS. When you concatenate any object with a string, the result is NaN. Interestingly, comparing two NaN values will yield false! ?? So, remember: NaN is not actually a number! ??
parseInt
This is quite funny! The parseInt method takes two parameters: the first is the string value, and the second is the radix (or base). Essentially, this method attempts to convert the input to the specified base. The funny behavior occurs when you pass null and any base between 24 and 30, leading to the unexpected result shown in the code below.
"b" + "a" + +"a" + "a";
To the end, this is my favorite ??, look at the result of the result the expression in the snippet below:
There are many quirky and funny behaviors in JavaScript, and as JS developers, it's essential to understand them to prevent errors. I hope you enjoy this and thanks for your time!
Senior Front-end Software Engineer | Mobile Developer | ReactJS | React Native | TypeScript | NodeJS
5 个月Very Interesting, nice share.