# Javascript – The Weird Parts

JavaScript is a powerful and versatile programming language that has been widely adopted by developers around the world. However, as with any programming language, javascript possesses certain quirks and weird parts that can cause confusion and frustration for developers. One such example is the behavior of the built-in JavaScript functions and operators when dealing with certain values.

One of the most common examples of this is the `isNaN()` function, which is used to determine if a given value is not a number. However, when used in combination with the `parseFloat()` function, the result can be quite unexpected. For example, the following code returns true:

`!isNaN(parseFloat('Infinity')) // true`
This is because `parseFloat('Infinity')` returns Infinity, which is a valid number in JavaScript, and `isNaN(Infinity)` returns false. This means that the ! operator negates the result, resulting in true.

Another example of unexpected behavior is the typeof operator, which is used to determine the type of a given value. However, when used with certain values, the results can be quite surprising. For example, the following code returns true:

`typeof NaN === 'number' // true `
This is because NaN is a special value in JavaScript that represents “Not-A-Number”. However, it is also considered a number type, which can cause confusion for developers.

Another example of unexpected behavior is the typeof operator when used with the null value, which returns “object”:

`typeof null === 'object' // true`
This is because null was initially considered as an object by developers and it was intended to represent no value. but later it is considered as a separate type.

Additionally, the typeof operator when used with Math, returns “object”

`typeof Math === 'object' // true`
Even though `Math` is not a typical object, it is considered as an object.

Finally, when used with a class, `typeof` returns “function”

`typeof MyClass === 'function' // true`
This is because, in javascript, classes are functions and the class syntax is just a shorthand for declaring a constructor function.

Lastly, the typeof operator when used with the `new Date()` returns “object”

`typeof new Date() === 'object' // true`
Even though `new Date()` returns a date object, it is considered as an object in javascript.

In conclusion, JavaScript is a powerful and versatile programming language, but it has its share of quirks and unexpected behaviors. The examples mentioned in this article are just a few examples of how the built-in functions and operators can produce unexpected results when dealing with certain values. It’s important for developers to understand these behaviors and take them into account when writing code to avoid confusion and unexpected bugs.
{"ft_lang_label":"__label__en","ft_lang_prob":0.8950609,"math_prob":0.7697097,"size":2725,"snap":"2023-40-2023-50","text_gpt3_token_len":537,"char_repetition_ratio":0.12127894,"word_repetition_ratio":0.10070258,"special_character_ratio":0.20366973,"punctuation_ratio":0.106471814,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9500194,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-09-28T01:20:50Z\",\"WARC-Record-ID\":\"<urn:uuid:3d418b5d-3a47-4422-9f85-b57af18d400c>\",\"Content-Length\":\"94262\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:07b4978c-ae02-4fb7-9381-776df6537214>\",\"WARC-Concurrent-To\":\"<urn:uuid:51ec1fd8-0fd6-4c1d-b535-b3f677472785>\",\"WARC-IP-Address\":\"212.1.211.245\",\"WARC-Target-URI\":\"https://imraan.in/til/javascript-the-weird-parts/\",\"WARC-Payload-Digest\":\"sha1:XU5UCX6EOB43WEPU7SQF5SKP7MQT4KFA\",\"WARC-Block-Digest\":\"sha1:MKES5E4BMRKQQA4XDARE4H5FYQ67O3AZ\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-40/CC-MAIN-2023-40_segments_1695233510334.9_warc_CC-MAIN-20230927235044-20230928025044-00151.warc.gz\"}"}