JavaScript is Crazy - Part 2

JavaScript is Crazy - Part 2

·

2 min read

Hello Folks 👋

What’s up friends, this is SnowBit here. I am a young passionate and self-taught developer and have an intention to become a successful developer.

Today, I am here again with a crazy thing in JavaScript.

So, let’s get started.

console.log(Math.max())

As we all know the biggest positive number is ∞ (infinity). So the out of the above code snippet should be positive Infinity. For better understanding, you can see the attached graph

graph

console.log(Math.max())
// -Infinity

But, as we know JavaScript is crazy 🤪; The output of this code is -Infinity. Don't believe it? check out the demo - https://jsfiddle.net/ce0hkoLs/

Now, here come Math.min() it is converse of Math.max

As we all know that lowest negative number is -∞(-infinity), but we know that’s not the case.

console.log(Math.min())
// Infinity

We all know simple math, right? Now again we have a crazy thing with mathematics in JavaScript.

console.log(0.5 + 0.1 == 0.6)
// true

Yes, 0.5 + 0.1 == 0.6 is true, isn’t it?

Now here comes some thing crazy,

console.log(0.1 + 0.2 == 0.3)

As we know, 0.1 + 0.2 == 0.3 is true, but JavaScript don’t think that. Somehow, JavaScript thinks it is false, I actually don’t know the exact reason for that let me know in the comments if you know it.

There, the output will be,

console.log(0.1 + 0.2 == 0.3)
// false

Try it - https://jsfiddle.net/feahj1s2/


Thank you for reading, have a nice day! Your appreciation is my motivation 😊

Â