WTFJS – a list of funny and tricky JavaScript examples
&gt; If you are a professional developer, you can consider these examples as a great resource for interview questions and quizzes for newcomers in your company<p>No, do not consider these examples as a &quot;great&quot; resource for interview questions. They are nothing more than tricks and hacks abusing the bad aspects of the language and anyone who includes them in an interview has failed in screening JavaScript developers, at least in my book.<p>A JS developer should understand that JavaScript has some flawed, unfixable core concepts and educate themselves on how to avoid them, not use them in actual production code or memorize every coercion scenario.<p>Some simple rules:<p>1. Always use referential equality checks (triple equal `===`). In idiomatic JS you can also use double equality only when explicitly checking against undefined or null (foo == null). It&#x27;s the only use of abstract equality that I find acceptable.<p>2. Learn how the `this` execution context works. Kyle Simpson explains it very well in YDKJS (<a href="https:&#x2F;&#x2F;github.com&#x2F;getify&#x2F;You-Dont-Know-JS&#x2F;blob&#x2F;master&#x2F;this & object prototypes&#x2F;ch2.md" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;getify&#x2F;You-Dont-Know-JS&#x2F;blob&#x2F;master&#x2F;this%...</a>). There are four simple rules that matter and are straightforward to grasp.<p>3. Familiarize yourself with how type coercion works in JS but avoid it. The spec is quite easy to follow in this matter and follows very specific, documented rules. e.g.:<p><a href="https:&#x2F;&#x2F;www.ecma-international.org&#x2F;ecma-262&#x2F;8.0&#x2F;index.html#sec-additive-operators" rel="nofollow">https:&#x2F;&#x2F;www.ecma-international.org&#x2F;ecma-262&#x2F;8.0&#x2F;index.html#s...</a> 
<a href="https:&#x2F;&#x2F;www.ecma-international.org&#x2F;ecma-262&#x2F;8.0&#x2F;index.html#sec-abstract-equality-comparison" rel="nofollow">https:&#x2F;&#x2F;www.ecma-international.org&#x2F;ecma-262&#x2F;8.0&#x2F;index.html#s...</a><p>Use strictly as reference.<p>4. Stop using plain ES5, the language currently is ES2017. ES2015 and beyond provide modern constructs that make most of ES5&#x27;s weirdness obsolete. For example, never use `var` anymore, `const` and `let` are superior initializers.<p>By following the above rules a JS developer should be fine in 99% of cases, in my experience. Yes, JavaScript will possibly implode on you on the rest 1%, but I&#x27;d be hard pressed to find a (similarly popular) language that doesn&#x27;t. If one finds that to be unacceptable, enabling types via TypeScript or Flow should make their life even easier.