Skip to content

Commit c1907c8

Browse files
committed
adding more tricky questions
1 parent 54a7f48 commit c1907c8

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

Javascript/Tricky-JS-Problems/Collection-of-Tricky-JS-Questlions.md

+38-1
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,47 @@ The site has detailed explanations as well as information on how to fix the prob
191191

192192
---
193193

194-
Question: typeof(NaN)
194+
### Question: typeof(NaN)
195195

196196
**Answer:**"number"
197197

198+
#### Further Explanations
199+
200+
###### In addition to the question - Why is `NaN === NaN` or `NaN == NaN` returning false.
201+
202+
It is not a peculiarity of javascript but common computer science principle.
203+
204+
From http://en.wikipedia.org/wiki/NaN:
205+
206+
> There are three kinds of operation
207+
> which return NaN:
208+
>
209+
> Operations with a NaN as at least one operand
210+
>
211+
> Indeterminate forms
212+
>
213+
> - The divisions 0/0, ∞/∞, ∞/−∞, −∞/∞, and −∞/−∞
214+
> - The multiplications 0×∞ and 0×−∞
215+
> - The power 1^∞
216+
> - The additions ∞ + (−∞), (−∞) + ∞ and equivalent subtractions.
217+
>
218+
> Real operations with complex results:
219+
>
220+
> - The square root of a negative number
221+
> - The logarithm of a negative number
222+
> - The tangent of an odd multiple of 90 degrees (or π/2 radians)
223+
> - The inverse sine or cosine of a number which is less than −1 or
224+
> greater than +1.
225+
226+
All these values may not be the same. A simple test for a NaN is to test `value == value` is false.
227+
228+
#### More Explanations
229+
230+
`NaN != NaN` because they are not necessary the SAME non-number. Thus it makes a lot of sense...
231+
Also why floats have both +0.00 and -0.00 that are not the same. Rounding may do that they are actually not zero.
232+
233+
As for typeof, that depends on the language. And most languages will say that NaN is a float, double or number depending on how they classify it... I know of no languages that will say this is an unknown type or null.
234+
198235
---
199236

200237
Question: 2 in [1,2]

0 commit comments

Comments
 (0)