{"id":749,"date":"2019-05-10T22:06:59","date_gmt":"2019-05-10T22:06:59","guid":{"rendered":"https:\/\/thinkcolorful.org\/?p=749"},"modified":"2024-12-13T19:47:46","modified_gmt":"2024-12-13T19:47:46","slug":"revisiting-javascript-some-lols","status":"publish","type":"post","link":"https:\/\/thinkcolorful.org\/?p=749","title":{"rendered":"Revisiting Javascript &#038;&#038; some lols"},"content":{"rendered":"\n<p><br>I&#8217;ve been working with Javascript off and on for years now.  During my internship I wanted to update my knowledge since I was not familiar with <a href=\"https:\/\/www.w3schools.com\/Js\/js_es6.asp\">ES6<\/a> and <a href=\"https:\/\/nodejs.org\/\">Node.js<\/a>.  My mentor taught themselves Javascript and Node so they recommended a few books and exercises I could do. I took them up on that offer and am reading <a href=\"https:\/\/eloquentjavascript.net\/\">Eloquent Javascript<\/a>. <\/p>\n\n\n\n<!--more-->\n\n\n\n<p><a href=\"https:\/\/eloquentjavascript.net\/01_values.html\">Chapter one<\/a> reminded me of this really funny article I read in Usenix by Professor James Mickens. Here are some of his gems:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p> \u25c6 JavaScript is dynamically typed, and its aggressive type coercion rules were apparently designed by Monty Python. For example, 12 == \u201c12\u201d because the string is coerced into a number. This is a bit silly, but it kind of makes sense. Now consider the fact that null == undefined. That is completely janky; a reference that points to null is not undefined\u2014IT IS DEFINED AS POINTING TO THE NULL VALUE. And now that you\u2019re warmed up, look at this: \u201c\\r\\n\\t\u201d == false. Here\u2019s why: the browser detects that the two operands have different types, so it converts false to 0 and retries the comparison. The operands still have different types (string and number), so the browser coerces \u201c\\r\\n\\t\u201d into the number 0, because somehow, a non-zero number of characters is equal to 0. Voila\u20140 equals 0! AWESOME. That explanation was like the plot to Inception, but the implanted idea was \u201cthe correctness of your program has been coerced to false.\u201d<\/p><p><br> \u25c6 Hello, kind stranger\u2014let me keep you warm during this cold winter night! Did you know that JavaScript defines a special NaN (\u201cnot a number\u201d) value? This value is what you get when you do foolish things like parseInt(\u201cBatmanIsNotAnInteger\u201d). In other words, NaN is a value that is not indicative of a number. However, typeof(NaN) returns\u2026 \u201cnumber.\u201d A more obvious return value would be \u201cHAIL BEELZEBUB, LORD OF DARKNESS,\u201d but I digress.<\/p><p><br> \u25c6 By the way, NaN != NaN, so Aristotle was wrong about that whole \u201cLaw of Identity\u201d thing.<\/p><p><br> \u25c6 Also, JavaScript defines two identity operators (=== and !== operators) which don\u2019t perform the type coercion that the standard equality operators do; however, NaN !== NaN. So, basically, don\u2019t use numbers in JavaScript, and if you absolutely have to use numbers, implement a software-level ALU. It\u2019s slow, but it\u2019s the only way to be sure<\/p><cite><a href=\"http:\/\/scholar.harvard.edu\/files\/mickens\/files\/towashitallaway.pdf\">To Wash It All Away<\/a>  by James Mickens Pg 7<\/cite><\/blockquote>\n\n\n\n<p>LOL &#8230; After doing some C, and looking back on Javascript&#8217;s quirkiness I definitely sympathize with his point of view. <\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><br><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been working with Javascript off and on for years now. During my internship I wanted to update my&#46;&#46;&#46;<\/p>\n","protected":false},"author":2,"featured_media":1332,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[214,10],"tags":[],"class_list":["post-749","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","category-programming"],"_links":{"self":[{"href":"https:\/\/thinkcolorful.org\/index.php?rest_route=\/wp\/v2\/posts\/749","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thinkcolorful.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thinkcolorful.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thinkcolorful.org\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/thinkcolorful.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=749"}],"version-history":[{"count":8,"href":"https:\/\/thinkcolorful.org\/index.php?rest_route=\/wp\/v2\/posts\/749\/revisions"}],"predecessor-version":[{"id":1077,"href":"https:\/\/thinkcolorful.org\/index.php?rest_route=\/wp\/v2\/posts\/749\/revisions\/1077"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/thinkcolorful.org\/index.php?rest_route=\/wp\/v2\/media\/1332"}],"wp:attachment":[{"href":"https:\/\/thinkcolorful.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=749"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thinkcolorful.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=749"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thinkcolorful.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=749"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}