How Can Data Visualization Improve Local Conditions?

On a dedicated channel, #dvs-topics-in-data-viz, in the Data Visualization Society Slack, our members discuss questions and issues pertinent to the field of data visualization. Discussion topics…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Difference between isNaN and Number.isNaN

Almost everyone knows what `isNaN` is and how to use it. It means “ is that thing that looks like a number, really a number or not?” It returns true if given is “Not a Number”. I assume you got the point. Ok, now here is the deal; what is the difference between isNaN and Number.isNaN?

Let’s start with isNaN. This is a global function you can call from everywhere. Let’s see it in action:

It is that simple but there are some misdirections. Here are the examples:

As you can see according to isNaN implementation treats string value as number and returns the result based on this.. Check `isNaN(‘blabla’)`

So what?

In my case I have a method which accepts two parameters as number type and do some animation on scaling of target object. Somehow after doing little refactoring I got weird behaviour. Yes, I should have written unit tests, shame on me. Anyway, for some cases the method receives undefined as parameters. So I need to check them.

I wrote this:

My carelessness leads me to wrong logic. Because Number.isNaN(undefined) will return me false. (old isNaN(undefined) returns true) So I changed like this:

So it seems to be working. But I wanted to care every possible failure. Maybe I might receive null instead of undefined. If I receive null my logic will fail. Why?

I think you see the thing. So I updated the code like this:

My goal was checking two values against to be undefined or null. And my journey ends up writing that article and updating my knowledge. The implementation is not fancy I know but the journey was educative.

Add a comment

Related posts:

Strategies for paying college

Although college can be an investment into your future, it cost’s alot of your time and money. Many people become entrenched by this debt for decades, trying to pay off their schooling. However…

Why You Need to Stop Letting Instamoms Make you Feel Bad!

I know you follow them, those moms, on social media whose lives are seemingly perfect. Their homes are impeccably organized and decorated. Their hair, makeup, and outfits are always perfectly done…

Nabil X For Entebbe Mayor

Nabil Albert Ariho Rugasira aka Nabil X is a dedicated educator, husband, father, and equestrian black man. Nabil X is a firm believer in family, religion, and state. He’s worked on several political…