DEV Community

Discussion on: Some Strange Concept of JavaScript

Collapse
 
joaolss profile image
João Lucas Silva

Nice article, it would be good to explain why such behaviors, for example isNaN actually makes use of js been weakly typed (js will try to convert anything, so if it expects a number, it will try to convert what you pass to a number) so isNaN("foo") = true, but isNaN("16") = false, because Number("foo") = NaN, but Number("16") = 16 so this is not a bug, or a flaw, it's just implicit conversion in action....also the fact that typeof null = "object", although controversial, is because how js was thought to be used, first everything is a object (including numbers and string, although treated as primitives) so null was conceived to be used as "an object with no defined value" and undefined was conceived to be "the absence of an object, or a object which was declared, but not yet initialized" that's why if you try retrieving a attribute that doesn't exist, it's value is undefined and that's why in json you have null but not undefined becaude you can have a object that has no value, but you can't have a object that doesn't exist....perhaps those kind of explanations were beyond the scope of the post, but i think they add to the undestanding behind the language and how it works, instead of just this feeling that people who created it and who manages it are just dumb hahah

Collapse
 
j471n profile image
Jatin Sharma

Thanks for you suggestion man, I have edited that part. :)