Skip navigation

In Javascript subtracting a string 5 from numeric 5 is legal and it will give you the correct result !!.

But when subtracting 5 from a string “five” it will not provide you the correct answer but javascript will not throw any error either!. In fact, it will return a value !!. The value is NaN (Not a number) and its type is number!!!.

alert(5-'5');      \\ 0
alert(5-'five');   \\ NaN (no errors)
alert(typeof NaN); \\ number

If a number is divided by zero, javascript returns a numeric value!!! The value is infinite. Yes it is of type number!!!

alert(5/0);   \\ infinity
alert(typeof infinity); \\ number

So, in javascript not only 1, 2, 3, etc., are numbers but also NaN and infinite!!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: