An open API service indexing awesome lists of open source software.

https://github.com/rofrol/javascript-wtf-koans


https://github.com/rofrol/javascript-wtf-koans

Last synced: 6 months ago
JSON representation

Awesome Lists containing this project

README

          

# Quotes

> Writing Javascript is like trying to make up with a pissed off girl.
> You try something, doing your best, and ask "Everything ok?"
> Girl/Javascript: "Fine."
> And then you just have to hope "Fine" means fine and not "I'mma cut you while you sleep".
> -- KillaCoder https://what.thedailywtf.com/t/javascript-gotchas-thread/2671/66

> You always run into problems when you design language features around the assumption that your users will mostly be idiots
> -- Rob Van Dam http://stackoverflow.com/questions/1995113/strangest-language-feature#comment1924259_2003277

# WTF links

- http://stackoverflow.com/questions/1995113/strangest-language-feature
- https://github.com/brianleroux/wtfjs/tree/master/posts
- http://www.smashingmagazine.com/2011/05/10-oddities-and-secrets-about-javascript/
- http://www.evotech.net/blog/2008/10/13-javascript-gotchas/#null
- http://www.codeproject.com/Articles/182416/A-Collection-of-JavaScript-Gotchas
- http://tech.domain.com.au/2015/07/type-coercion-in-javascript/
- https://what.thedailywtf.com/t/javascript-gotchas-thread/2671/65
- http://martin-thoma.com/javascript-wtf/
- (The Strict Equality Comparison Algorithm)[http://ecma-international.org/ecma-262/5.1/#sec-11.9.6]
- https://www.destroyallsoftware.com/talks/wat
- http://davidwalsh.name/fixing-coercion
- https://www.safaribooksonline.com/library/view/you-dont-know/9781491905159/ch04.html
- http://www.2ality.com/2013/04/12quirks.html
- http://cwestblog.com/2014/02/25/javascript-testing-for-negative-zero/
- https://wiki.theory.org/YourLanguageSucks#JavaScript_sucks_because
- `{} + "wtf"` `console.log(eval('{}+"wtf"'))` https://www.reddit.com/r/javascript/comments/3z74ok/will_let_eventually_replace_var/cyk8vjq

# How to defend yourself

- http://eslint.org/docs/1.0.0/rules/no-implicit-coercion.html
- https://github.com/airbnb/javascript
- http://stackoverflow.com/questions/27595749/douglas-crockford-on-class-free-oop-in-javascript
- http://www.breck-mckye.com/blog/2014/05/why-i-prefer-parasitic-inheritance/
- (Douglas Crockford: The Better Parts - JSConfUY 2014)[https://www.youtube.com/watch?v=bo36MrBfTk4]
- (Nordic.js 2014 • Douglas Crockford - The Better Parts)[https://www.youtube.com/watch?v=PSGEjv3Tqo0]
- https://www.udemy.com/the-best-parts-of-javascript-functions-to-error-free-code/
- http://www.amazon.com/JavaScript-The-Good-Parts-ebook/dp/B0026OR2ZY/
- http://stackoverflow.com/questions/18922197/using-parasitic-inheritance-in-javascript-is-it-possible-to-implement-introspec
- http://www.crockford.com/javascript/inheritance.html
- http://blog.chewxy.com/2014/02/24/what-every-javascript-developer-should-know-about-floating-point-numbers/

# Is Crkockford wrong on DEC64?

- https://www.reddit.com/r/programming/comments/28r8xt/dec64_is_intended_to_be_the_only_number_type_in/
- https://news.ycombinator.com/item?id=7365812

## Examples

### Some WTF moments in Javascript, courtesy of Gary Bernhardt

```javascript
var foo = ["10", "10", "10"];
foo.map(parseInt);
// Returns [ 10, NaN, 2 ]

[] + [] // ""
[] + {} // {}
{} + [] // 0
{} + {} // NaN

var a = {};
a[[]] = 2;
alert(a[""]); // alerts 2

alert(Array(16).join("wat" - 1) + " Batman!");
```

https://news.ycombinator.com/item?id=8850540

### Contrived usage of comma operator and behaviour of parseInt - what's the output?

```javascript
parseInt((null, {test: 99}, false, 'J,uhuru', /asdf/, function() { giantInflatableShark(!!'!!'); },
'A,spock', '0') + ('cheese' / 'toast', new Date(), Number('hello'),
'x') + (undefined, [1, 2, 3], new Array(5), 1e4, 'F,captainkirk'))
```
https://gist.github.com/insin/1183916