<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mikhail Korolev</title>
    <description>The latest articles on DEV Community by Mikhail Korolev (@mkrl).</description>
    <link>https://dev.to/mkrl</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F131739%2Fb7e05ee6-5b4e-4c0b-bc0b-d7012389ca86.jpg</url>
      <title>DEV Community: Mikhail Korolev</title>
      <link>https://dev.to/mkrl</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mkrl"/>
    <language>en</language>
    <item>
      <title>Overengineering hackaton is now live!</title>
      <dc:creator>Mikhail Korolev</dc:creator>
      <pubDate>Fri, 02 Aug 2019 08:23:53 +0000</pubDate>
      <link>https://dev.to/mkrl/overengineering-hackaton-is-now-live-3blg</link>
      <guid>https://dev.to/mkrl/overengineering-hackaton-is-now-live-3blg</guid>
      <description>&lt;p&gt;Looking to set your inner demons free and finally lay down that multidimensional project architecture you've seen in your dreams? r/ProgrammerHumor is hosting a hackaton with nothing but "overengineering" as a topic!&lt;/p&gt;

&lt;p&gt;A great chance to have some fun and get a piece of that 500$ Digital Ocean credits. &lt;br&gt;
All the relevant info can be found &lt;a href="https://www.programmerhumor.org/Hackathon"&gt;here&lt;/a&gt; or in this &lt;a href="https://www.reddit.com/r/ProgrammerHumor/comments/ckhow3/the_very_first_programmerhumor_hackathon_is_now/"&gt;subreddit post&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can step in as a group of up to 4 people too. So, if you are looking for a team, a good place to find your DEV partner is in this post's comment section.&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>watercooler</category>
    </item>
    <item>
      <title>Atomic-powered Fibonacci indentation</title>
      <dc:creator>Mikhail Korolev</dc:creator>
      <pubDate>Mon, 04 Mar 2019 18:01:34 +0000</pubDate>
      <link>https://dev.to/mkrl/atomic-powered-fibonacci-indentation-2cpb</link>
      <guid>https://dev.to/mkrl/atomic-powered-fibonacci-indentation-2cpb</guid>
      <description>&lt;p&gt;Atom package that converts the spacing for each successive indentation according to the Fibonacci sequence.&lt;/p&gt;

&lt;p&gt;Quite recently I stumbled upon &lt;a href="https://github.com/dodie/vim-fibo-indent" rel="noopener noreferrer"&gt;this vim plugin&lt;/a&gt; that does the same job (but, honestly, way better), plus after a short discussion, I had an epiphany that people have never heard about this method of making their code look great.&lt;/p&gt;


&lt;div class="liquid-comment"&gt;
    &lt;div class="details"&gt;
      &lt;a href="/eidsonator"&gt;
        &lt;img class="profile-pic" src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F48157%2F1ea6fa03-5479-4e5f-9e70-0eca60fb6df4.jpeg" alt="eidsonator profile image"&gt;
      &lt;/a&gt;
      &lt;a href="/eidsonator"&gt;
        &lt;span class="comment-username"&gt;Todd Eidson&lt;/span&gt;
      &lt;/a&gt;
      &lt;span class="color-base-30 px-2 m:pl-0"&gt;•&lt;/span&gt;

&lt;a href="https://dev.to/eidsonator/comment/95i2" class="comment-date crayons-link crayons-link--secondary fs-s"&gt;
  &lt;time class="date-short-year"&gt;
    Mar 1 '19
  &lt;/time&gt;

&lt;/a&gt;

    &lt;/div&gt;
    &lt;div class="body"&gt;
      

&lt;p&gt;That's great! First I'd heard of Fibonacci Indentation.  I like it!&lt;/p&gt;



    &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;So, here it is.&lt;br&gt;
&lt;a href="https://atom.io/packages/fibonacci-indent" rel="noopener noreferrer"&gt;Atom plugin page&lt;/a&gt;.&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/mkrl" rel="noopener noreferrer"&gt;
        mkrl
      &lt;/a&gt; / &lt;a href="https://github.com/mkrl/fibonacci-indent" rel="noopener noreferrer"&gt;
        fibonacci-indent
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Atom package that adjusts your indentation according to the Fibonacci sequence
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;Fibonacci-indent&lt;/h1&gt;
&lt;/div&gt;
&lt;p&gt;An Atom plugin that serves a single purpose: indent your currently selected code based on the Fibonacci sequence.&lt;/p&gt;
&lt;p&gt;&lt;a rel="noopener noreferrer" href="https://github.com/mkrl/fibonacci-indentdemo.gif"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fmkrl%2Ffibonacci-indentdemo.gif" alt="Demo GIF"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;How it works&lt;/h2&gt;
&lt;/div&gt;
&lt;p&gt;After applying to the pre-indented code (with either tabs or spaces), 2 of each space characters (or 1 tab if you're that kind of guy) at the beginning of the line will be converted to the corresponding Fibonacci sequence number
Feel free to use your code beautifier of choice before fibonazing your tabs.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Why?&lt;/h2&gt;

&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;It makes your deeply nested code look like spaceships.&lt;/li&gt;
&lt;li&gt;If your co-worker has spawned another russian doll method, feel free to use this plugin to show how good it actually looks for other people.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Please don't use this on any actual code you're intended to share with other human beings in serious projects.
This can also break indent-based languages like Python or Ruby so please be careful.&lt;/p&gt;
&lt;p&gt;Somehow inspired by this &lt;a href="https://github.com/dodie/vim-fibo-indent" rel="noopener noreferrer"&gt;vim plugin&lt;/a&gt; that…&lt;/p&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/mkrl/fibonacci-indent" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;(wanted to save it for April 1st, but couldn't resist)&lt;/p&gt;

</description>
      <category>githunt</category>
      <category>atom</category>
      <category>showdev</category>
    </item>
    <item>
      <title>JavaScript quirks in one image from the Internet</title>
      <dc:creator>Mikhail Korolev</dc:creator>
      <pubDate>Fri, 01 Mar 2019 16:55:46 +0000</pubDate>
      <link>https://dev.to/mkrl/javascript-quirks-in-one-image-from-the-internet-52m7</link>
      <guid>https://dev.to/mkrl/javascript-quirks-in-one-image-from-the-internet-52m7</guid>
      <description>&lt;p&gt;Recently I stumbled upon this picture on Google Images:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3hzq5xhiocmb7pbcz3bx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3hzq5xhiocmb7pbcz3bx.png" alt="Thanks for inventing JavaScript"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The man on the picture is Brendan Eich by the way, the creator of JavaScript and a co-founder of the Mozilla project.&lt;/p&gt;

&lt;p&gt;Even with some of the examples are not really related to the language itself, I still find it interesting enough to give it a short breakdown, considering it doesn't make much sense for some people with the classic "strict language"-only programming background.&lt;/p&gt;

&lt;h2&gt;
  
  
  The breakdown
&lt;/h2&gt;

&lt;p&gt;Starting with the "boring" parts:&lt;/p&gt;

&lt;h4&gt;
  
  
  Floating-point arithmetic
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;gt; 9999999999999999
&amp;lt; 10000000000000000

&amp;gt; 0.5+0.1==0.6
&amp;lt; true

&amp;gt; 0.1+0.2==0.3
&amp;lt; false


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Nothing really surprising here, it's an old concept that has been around for quite a while. And it is, of course, not related to JavaScript "features". Instead of trying to explain it here, I'll just leave a link the to &lt;a href="https://floating-point-gui.de/" rel="noopener noreferrer"&gt;this great&lt;/a&gt; "explainlikeimfive" website dedicated exclusively to explaining floating-point math.&lt;/p&gt;

&lt;h4&gt;
  
  
  Not A Number is a Number
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;gt; typeof NaN
&amp;lt; "number"


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;What is "NaN" after all? It is, in fact, a representation of a specific value that can't be presented within the limitations of the numeric type (the only JS numeric primitive is, in fact &lt;code&gt;float&lt;/code&gt;). NaN was introduced in the IEEE 754 floating-point standard. &lt;/p&gt;

&lt;p&gt;So, it's just a number that a computer can't calculate in this particular environment. &lt;/p&gt;

&lt;h4&gt;
  
  
  Type conversion
&lt;/h4&gt;

&lt;p&gt;JavaScript is a dynamic type language, which leads to the most hated "why it this like that" debugging sessions for those who is not familiar with the silent (implicit) type coercion. &lt;/p&gt;

&lt;p&gt;The simple part: strict equality with &lt;code&gt;===&lt;/code&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;gt; true === 1
&amp;lt; false


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Strict equality compares two values. Neither value is implicitly converted to some other value before being compared. If the values have different types, the values are considered unequal. Boolean variable is not equal to 1, which is a number.&lt;/p&gt;

&lt;p&gt;On the other hand, there is this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;gt; true == 1
&amp;lt; true


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This is an example of &lt;em&gt;implicit type coercion&lt;/em&gt;. Implicit type coercion is being triggered when you apply operators to values of different types: &lt;code&gt;2+'2'&lt;/code&gt;, &lt;code&gt;'true'+false&lt;/code&gt;, &lt;code&gt;35.5+new RegExp('de*v\.to')&lt;/code&gt; or put a value into a certain context which expects it to be of a certain type, like &lt;code&gt;if (value) {&lt;/code&gt; (coerced to &lt;code&gt;boolean&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;JavaScript type conversion is not the most trivial part, so I would suggest further reading like &lt;a href="https://medium.freecodecamp.org/js-type-coercion-explained-27ba3d9a2839" rel="noopener noreferrer"&gt;this great article&lt;/a&gt; by Alexey Samoshkin and &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness" rel="noopener noreferrer"&gt;this little MDN doc&lt;/a&gt; on equality comparisons. There is also this &lt;a href="https://dorey.github.io/JavaScript-Equality-Table/" rel="noopener noreferrer"&gt;equality comparison cheatsheet&lt;/a&gt; that may come in handy. &lt;/p&gt;

&lt;p&gt;Anyway, let's get back to our picture.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;gt; [] + []
&amp;lt; ""


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;There are 2 types of variables in JS: objects and primitives, with primitives being &lt;code&gt;number&lt;/code&gt;, &lt;code&gt;string&lt;/code&gt;, &lt;code&gt;boolean&lt;/code&gt;, &lt;code&gt;undefined&lt;/code&gt;, &lt;code&gt;null&lt;/code&gt; and &lt;code&gt;symbol&lt;/code&gt;. Everything else is an object, including functions and arrays.&lt;/p&gt;

&lt;p&gt;When an expression with operators that call implicit conversion is being executed, the entire expression is being converted to one of three primitive types:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;string&lt;/li&gt;
&lt;li&gt;number&lt;/li&gt;
&lt;li&gt;boolean&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Primitive conversions follow certain rules that are &lt;a href="https://www.w3schools.com/js/js_type_conversion.asp" rel="noopener noreferrer"&gt;pretty straightforward&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;As for the objects: In case of &lt;code&gt;boolean&lt;/code&gt;, any non-primitive value is always coerced to &lt;code&gt;true&lt;/code&gt;. For &lt;code&gt;string&lt;/code&gt; and &lt;code&gt;number&lt;/code&gt;, the following internal operation &lt;a href="https://tc39.github.io/ecma262/#sec-toprimitive" rel="noopener noreferrer"&gt;ToPrimitive(input, PreferredType)&lt;/a&gt; is being run, where optional &lt;code&gt;PreferredType&lt;/code&gt; is either &lt;code&gt;number&lt;/code&gt; or &lt;code&gt;string&lt;/code&gt;. This executes the following algorithm:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;If input is already a primitive, return it as it is&lt;/li&gt;
&lt;li&gt;Otherwise, input is treated like an object. Call &lt;code&gt;input.valueOf()&lt;/code&gt;. Return if the result is a primitive.&lt;/li&gt;
&lt;li&gt;Otherwise, call &lt;code&gt;input.toString()&lt;/code&gt;. If the result is a primitive, return it.&lt;/li&gt;
&lt;li&gt;Otherwise, throw a TypeError.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Swap 2 and 3 if &lt;code&gt;PreferredType&lt;/code&gt; is &lt;code&gt;string&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Take a look at this pseudo-implementation of the above in actual JavaScript, plus the boolean conversion (the original is a &lt;a href="https://gist.github.com/samoshkin/baf070ab19b73f4f39ec54149fb37c30#file-js-to-primitive-internal-js" rel="noopener noreferrer"&gt;courtesy of Alexey Samoshkin&lt;/a&gt; via the article mentioned previously). &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;ToPrimitive&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;preferredType&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;

  &lt;span class="k"&gt;switch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;preferredType&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="nb"&gt;Boolean&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;toNumber&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="k"&gt;break&lt;/span&gt;
    &lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;toNumber&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;isPrimitive&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nc"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;isPrimitive&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;()))&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;isPrimitive&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;valueOf&lt;/span&gt;&lt;span class="p"&gt;()))&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;valueOf&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TypeError&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;toNumber&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;isPrimitive&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;valueOf&lt;/span&gt;&lt;span class="p"&gt;()))&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;valueOf&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;isPrimitive&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;()))&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TypeError&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;So, at the end of the day, the original &lt;code&gt;[] + [] == ""&lt;/code&gt; is being interpreted as:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="nc"&gt;ToPrimitive&lt;/span&gt;&lt;span class="p"&gt;([])&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nc"&gt;ToPrimitive&lt;/span&gt;&lt;span class="p"&gt;([])&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Both arrays return an empty string as a result of &lt;code&gt;toString([])&lt;/code&gt;. The final result is a  concatenation of two empty strings.  &lt;/p&gt;

&lt;p&gt;Now, onto the:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;gt; [] + {}
&amp;lt; "[object Object]"


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Because of the &lt;code&gt;String({})&lt;/code&gt; resulting in a &lt;code&gt;[object Object]&lt;/code&gt; the result is a simple concatenation of &lt;code&gt;""&lt;/code&gt; and &lt;code&gt;"[object Object]"&lt;/code&gt;. Simple enough. Now what the hell is going on here then?&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;gt; {} + []
&amp;lt; 0


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Turns out, JavaScript interprets the first &lt;code&gt;{}&lt;/code&gt; as a code block! When the input is being parsed from start to end, it treats &lt;code&gt;{&lt;/code&gt; as the beginning of the block, following by closing &lt;code&gt;}&lt;/code&gt; immediately. Hence, using our pseudo-implementation the previous example will be evaluated into the following:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="nc"&gt;ToPrimitive&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;[])&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;..which is 0. The &lt;code&gt;+&lt;/code&gt; is an unary prefix operator that converts the operand into a number. &lt;/p&gt;

&lt;p&gt;Loose equality &lt;code&gt;==&lt;/code&gt; and binary &lt;code&gt;+&lt;/code&gt; operators always trigger default &lt;code&gt;preferredType&lt;/code&gt;, which assumes numeric conversion (except Date that returns string). That explains &lt;code&gt;true+true+true===3&lt;/code&gt; and &lt;code&gt;true==1&lt;/code&gt;. Thus, as expected &lt;code&gt;true===1&lt;/code&gt; returns &lt;code&gt;false&lt;/code&gt; because there are no operators on the left side of the expression and &lt;code&gt;===&lt;/code&gt; does not trigger implicit type coercion. Same with &lt;code&gt;[]==0&lt;/code&gt; which is roughly equivalent to &lt;code&gt;Number([]) == 0&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Everything brings up interesting examples like the one we have here:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;gt; (!+[]+[]+![]).length
&amp;lt; 9


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Breaking it down,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;(!+[]) + [] + (![])&lt;/li&gt;
&lt;li&gt;!0 + [] + false&lt;/li&gt;
&lt;li&gt;true + [] + false&lt;/li&gt;
&lt;li&gt;true + '' + false&lt;/li&gt;
&lt;li&gt;'truefalse'&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;'truefalse'.length === 9 &lt;/p&gt;

&lt;p&gt;Very simple.&lt;/p&gt;

&lt;p&gt;And last (and the least, to be honest):&lt;/p&gt;

&lt;h4&gt;
  
  
  Math.max() &amp;lt; Math.min() ?
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;gt; Math.max()
&amp;lt; -Infinity
&amp;gt; Math.min()
&amp;lt; Infinity


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This &lt;em&gt;may&lt;/em&gt; be considered as a minor language flaw, in terms of returning a kind of an unexpected result from a function that wants certain arguments. &lt;/p&gt;

&lt;p&gt;But there actually is a little bit of some actual math behind that. &lt;/p&gt;

&lt;p&gt;Let's make a guess on how (probably) &lt;code&gt;Math.max()&lt;/code&gt; works and write down another imaginary transcript into actual JavaScript:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;max&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;temp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="kc"&gt;Infinity&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;arguments&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arguments&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;temp&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;temp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;temp&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now it kind of makes sense to return &lt;code&gt;-Infinity&lt;/code&gt; when no arguments are passed. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;-Infinity&lt;/code&gt; is an &lt;a href="https://en.wikipedia.org/wiki/Identity_element" rel="noopener noreferrer"&gt;identity element&lt;/a&gt; of &lt;code&gt;Math.max()&lt;/code&gt;. Identity element for a binary operation is an element that leaves any other element unchanged after applying said operation to both elements.&lt;/p&gt;

&lt;p&gt;So, 0 is the identity of addition, 1 is the identity of multiplication. &lt;code&gt;x+0&lt;/code&gt;and &lt;code&gt;x*1&lt;/code&gt; is always &lt;code&gt;x&lt;/code&gt;. Out of &lt;code&gt;-Infinity&lt;/code&gt; and &lt;code&gt;x&lt;/code&gt;, &lt;code&gt;x&lt;/code&gt; will always be the maximum number.&lt;/p&gt;

&lt;p&gt;There is an absolutely &lt;a href="https://charlieharvey.org.uk/page/why_math_max_is_less_than_math_min" rel="noopener noreferrer"&gt;gorgeous article&lt;/a&gt; by Charlie Harvey that deeply dives into this topic.&lt;/p&gt;




&lt;p&gt;Summing up, implicit type coercion is a very important concept you should always keep in mind. Avoid loose equality. Think about what are you comparing, use explicit conversion whenever possible. Consider switching to TypeScript if the above scares you :)&lt;/p&gt;

&lt;p&gt;And if you want to see more "wtf" JavaScript, there is a great resource called, literally, &lt;a href="https://github.com/denysdovhan/wtfjs" rel="noopener noreferrer"&gt;wtfjs&lt;/a&gt;, that is also available as a handbook via &lt;code&gt;npm&lt;/code&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>APIs you didn't know you needed</title>
      <dc:creator>Mikhail Korolev</dc:creator>
      <pubDate>Tue, 29 Jan 2019 19:07:06 +0000</pubDate>
      <link>https://dev.to/mkrl/apis-you-didnt-know-you-needed-38c</link>
      <guid>https://dev.to/mkrl/apis-you-didnt-know-you-needed-38c</guid>
      <description>&lt;p&gt;With everything recently being "as a service", there are a plenty of different data sources that can provide... stuff. Stuff as a service, of course. Behold a small collection of APIs you may or not have heard about.&lt;/p&gt;

&lt;h2&gt;
  
  
  Yes or no?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://yesno.wtf/#api" rel="noopener noreferrer"&gt;https://yesno.wtf/#api&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Making decisions is hard. Why won't you outsource this job to a third-party microservice to ensure that the they are as independent as possible? Returns "maybe" every 10.000th time as a bonus.&lt;/p&gt;

&lt;h2&gt;
  
  
  Taco API
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/evz/tacofancy-api" rel="noopener noreferrer"&gt;https://github.com/evz/tacofancy-api&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Are you in love with tacos? Can't decide what kind to make today? One HTTP request will get you a full recipe (with optional ingredients and categories of your choice). &lt;/p&gt;

&lt;h2&gt;
  
  
  Corporate bullshit
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/sameerkumar18/corporate-bs-generator-api" rel="noopener noreferrer"&gt;https://github.com/sameerkumar18/corporate-bs-generator-api&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Do you find it hard to talk to Highly Enterprise Customers? Does your manager's manager want you to present a new topic for a weekly "0.5% team effectiveness raise" meeting? This will get you covered.&lt;/p&gt;

&lt;h2&gt;
  
  
  It's like this for that!
&lt;/h2&gt;

&lt;p&gt;&lt;a href="http://itsthisforthat.com/api.php" rel="noopener noreferrer"&gt;http://itsthisforthat.com/api.php&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Another friend of yours quit the job and invested all the money and time into smart socks?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F39mgqfdb2l0ye1l6dsp4.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F39mgqfdb2l0ye1l6dsp4.PNG" alt="It's like this for that"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  ALL CAPS AS A SERVICE
&lt;/h2&gt;

&lt;p&gt;&lt;a href="http://shoutcloud.io/" rel="noopener noreferrer"&gt;http://shoutcloud.io/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;SHOUTING IS 100% THE WAY TO COMMUNICATE WHEN THINGS ARE IMPORTANT.&lt;/p&gt;

&lt;p&gt;Ruby gem, npm package and go libraries are also available.&lt;/p&gt;

&lt;h2&gt;
  
  
  Automate things that are important
&lt;/h2&gt;

&lt;p&gt;&lt;a href="http://www.foaas.com/" rel="noopener noreferrer"&gt;http://www.foaas.com/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Highly advanced and flexible RESTful API that accomplishes a common task of telling people to fuck off.&lt;/p&gt;

&lt;p&gt;Custom names, signatures and loads of other options are available. Having a hard time communicating with disturbing foreigners? i18n is supported, as well as SHOUTCLOUD integration listed above. &lt;/p&gt;

&lt;h2&gt;
  
  
  Lorem Ipsum
&lt;/h2&gt;

&lt;p&gt;If you are tired of the regular boring Lorem Ipsum filling your template layouts, take a look at &lt;a href="https://baconipsum.com/json-api/" rel="noopener noreferrer"&gt;Bacon Ipsum&lt;/a&gt; - a meaty dummy text API. If you are vegetarian, &lt;a href="http://skateipsum.com/" rel="noopener noreferrer"&gt;Skateboard-themed Ipsum&lt;/a&gt; or &lt;a href="http://baseballipsum.apphb.com/Home/RestApi" rel="noopener noreferrer"&gt;Baseball&lt;/a&gt; one will get you covered.&lt;/p&gt;

&lt;p&gt;And here is a &lt;a href="https://github.com/jaspervdj/lorem-markdownum#http-api" rel="noopener noreferrer"&gt;Markdown-flavoured&lt;/a&gt; Ipsum generator as a bonus.&lt;/p&gt;

&lt;h2&gt;
  
  
  Numbers
&lt;/h2&gt;

&lt;p&gt;&lt;a href="http://numbersapi.com/" rel="noopener noreferrer"&gt;http://numbersapi.com/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We all love numbers. If you are in love with a particular number or date, you might as well want to know more about it. 78? A total number of gifts in the song The Twelve Days of Christmas. &lt;/p&gt;

&lt;p&gt;And if you are bored, it is your chance to write a Slack plugin for PR notifications.&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&lt;p&gt;[thepracticaldev/dev.to] Pull request opened: #3 Klingon Code of Conduct&lt;br&gt;
Lines changed as much as the number of years in 235 lunations.&lt;/p&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Animals as a service.&lt;br&gt;
&lt;/h2&gt;

&lt;p&gt;The famous &lt;a href="https://thecatapi.com/" rel="noopener noreferrer"&gt;Cat API&lt;/a&gt; paired with &lt;a href="https://dog.ceo/dog-api/" rel="noopener noreferrer"&gt;Dog&lt;/a&gt; and &lt;a href=""&gt;Shibe&lt;/a&gt; API, as well as more lightweight random &lt;a href="https://randomfox.ca/floof/" rel="noopener noreferrer"&gt;fox&lt;/a&gt;, &lt;a href="https://aws.random.cat/meow" rel="noopener noreferrer"&gt;cat&lt;/a&gt; and &lt;a href="https://random.dog/woof.json" rel="noopener noreferrer"&gt;dog&lt;/a&gt; services will get you a heartwarming JSON response every time you need it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Donald Trump API
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://docs.tronalddump.io/" rel="noopener noreferrer"&gt;https://docs.tronalddump.io/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As the most acknowledged political figure of modern US, you can always expect people to keep record of what you said in a searchable database with an easy to parse output format. &lt;/p&gt;

&lt;p&gt;If you don't want to get political, there is also a simple &lt;a href="https://github.com/jamesseanwright/ron-swanson-quotes" rel="noopener noreferrer"&gt;Ron Swanson&lt;/a&gt; quotes API. And, of course a good supply of &lt;a href="https://api.chucknorris.io/" rel="noopener noreferrer"&gt;Chuck Norris facts&lt;/a&gt; that definitely comes in handy.&lt;/p&gt;

&lt;h2&gt;
  
  
  Everything you ever wanted to CURL about the food
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://spoonacular.com/food-api" rel="noopener noreferrer"&gt;https://spoonacular.com/food-api&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Recipes, ingredients, menu items, nutrition data. Mount a webcam inside your fridge, label your food with QR codes and automate your cooking suggestions based on what you have in stock.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dispose data with ease
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://devnull-as-a-service.com/code/" rel="noopener noreferrer"&gt;https://devnull-as-a-service.com/code/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;/dev/null in the cloud. Get rid of your unwanted bytes over POST requests. Free for up to 25GB/Month.&lt;/p&gt;

&lt;h2&gt;
  
  
  Spice up your placeholders
&lt;/h2&gt;

&lt;p&gt;Not exactly an API in the same way as the rest of the services mentioned previously, but something you can't easily walk past.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://placekitten.com/" rel="noopener noreferrer"&gt;http://placekitten.com/&lt;/a&gt;&lt;br&gt;
&lt;a href="http://www.fillmurray.com/" rel="noopener noreferrer"&gt;http://www.fillmurray.com/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.stevensegallery.com/" rel="noopener noreferrer"&gt;https://www.stevensegallery.com/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.placecage.com/" rel="noopener noreferrer"&gt;https://www.placecage.com/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fwww.fillmurray.com%2F1000%2F400" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fwww.fillmurray.com%2F1000%2F400" alt="Bill Murray placeholder"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Got other services the world should know about? &lt;/p&gt;

</description>
      <category>api</category>
      <category>productivity</category>
      <category>fun</category>
    </item>
  </channel>
</rss>
