Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ Thanks [Paul Irish](https://twitter.com/paul_irish) for the explanation.
Note that your code won't be highlighted :( If you'd like to figure out how to
get '```' to highlight, please help and submit PR! Thank you! - @DTrejo

I might have figured highlighting out, but it requires further editing on your side - [paulstelian97](http://github.com/paulstelian97)

the code
---

Expand Down
15 changes: 15 additions & 0 deletions src/html/get-wtfs-000wtfID/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ var exists = require('file-exists')
var arc = require('@architect/functions')
var layout = require('@wtfjs/theme')

marked.setOptions({
renderer: new marked.Renderer(),
highlight: function(code) {
return require('highlight.js').highlightAuto(code).value;
},
pedantic: false,
gfm: true,
tables: true,
breaks: false,
sanitize: false,
smartLists: true,
smartypants: false,
xhtml: false
});

function route(req, res) {
var filename = req.params.wtfID + '.md'
var filepath = path.join(__dirname, 'node_modules', '@wtfjs', 'md', filename)
Expand Down
6 changes: 3 additions & 3 deletions src/md/2010-02-12-almost-but-not-quite.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<code>
alert(111111111111111111111); // alerts 111111111111111110000
</code>
``` javascript
alert(111111111111111111111); // alerts 111111111111111110000
```
6 changes: 3 additions & 3 deletions src/md/2010-02-12-foonanny.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ Evaluted as “foo” + (+ “bar”), which converts “bar” to not a number.

Proposal to rename this site: NaNwtf

<code>
("foo" + + "bar") === "fooNaN" // true
</code>
``` javascript
("foo" + + "bar") === "fooNaN" // true
```
4 changes: 2 additions & 2 deletions src/md/2010-02-12-function-context-fun.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<code>
``` javascript
(x=[].reverse)() === window // true
</code>
```

- Thanks to [@tobeytailor](http://twitter.com/tobeytailor) for pointing out this beauty.
- Updated: an error is thrown when the code is executed in Chrome 49
4 changes: 2 additions & 2 deletions src/md/2010-02-12-maths-fun.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Clearly JavaScript is not the most beautiful, or intuitive, language for maths.

```
``` javascript
typeof NaN === 'number' // true
Infinity === 1/0 // true
0.1 + 0.2 === 0.3 // false
```
```
10 changes: 5 additions & 5 deletions src/md/2010-02-12-min-number-treachery.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<code>
Number.MIN_VALUE > 0;
// true? really? wtf.
</code>
``` javascript
Number.MIN_VALUE > 0;
// true? really? wtf.
```

It turns out that MIN_VALUE is the smallest number GREATER THAN ZERO, which of course totally makes sense.
It turns out that `MIN_VALUE` is the smallest number GREATER THAN ZERO, which of course totally makes sense.
8 changes: 4 additions & 4 deletions src/md/2010-02-12-not-a-number-is-a-number.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<code>
typeof NaN // number, of course.
</code>
``` javascript
typeof NaN // number, of course.
```

Now that makes sense.
Now that makes sense.
4 changes: 2 additions & 2 deletions src/md/2010-02-12-not-a-number-is-not-a-not-a-number.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Some argue this makes sense. Some ppl also like to sniff glue.

<code>
``` javascript
NaN === NaN // false
</code>
```
4 changes: 2 additions & 2 deletions src/md/2010-02-12-null-is-not-an-object.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
```
``` javascript
typeof null // object
null instanceof Object // false
```

Classic null is not an Object.
Classic null is not an Object.
4 changes: 2 additions & 2 deletions src/md/2010-02-12-parseint-treachery.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
```
``` javascript
parseInt('06'); // 6
parseInt('08'); // 0
```

This is because parseInt accepts a second argument for radix. If it is not supplied and the string starts with a 0 it will be parsed as an octal number. Riiiiiiight, of COURSE.
This is because parseInt accepts a second argument for radix. If it is not supplied and the string starts with a 0 it will be parsed as an octal number. Riiiiiiight, of COURSE.
4 changes: 2 additions & 2 deletions src/md/2010-02-13-null-is-not-falsy.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
```
``` javascript
[] == false; // true
"" == false; // true
null == false; // false, that's more like it
```
```
4 changes: 2 additions & 2 deletions src/md/2010-02-13-string-is-not-string.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
```
``` javascript
"string" instanceof String; // false.
// 'course it isn't not a string, it may look like a string
// but actually it's masquerading as a banana.
```

When is a string, not a string? When it’s a duck - [@rem](http://twitter.com/rem)
When is a string, not a string? When it’s a duck - [@rem](http://twitter.com/rem)
4 changes: 2 additions & 2 deletions src/md/2010-02-15-accidental-global.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
This one is fun and sneaky.

```
``` javascript
(function(){
var x = y = 1;
})();
alert(x); // undefined
alert(y); // 1 -- oops, auto-global!
```

It’s treated like: var x = (y = 1); thus, “y=1” creates an auto-global since there’s no binding “var” statement for it. Afterwards, that value gets copied into the properly defined local var “x”.
It’s treated like: var x = (y = 1); thus, “y=1” creates an auto-global since there’s no binding “var” statement for it. Afterwards, that value gets copied into the properly defined local var “x”.
8 changes: 4 additions & 4 deletions src/md/2010-02-15-careful.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<code>
[] == ![] // true
</code>
``` javascript
[] == ![] // true
```

Arrays evaluate as true in a boolean condition so this does make some sense even if it doesn’t read very well! Thanks to [@collintmiller](http://twitter.com/collintmiller)!
Arrays evaluate as true in a boolean condition so this does make some sense even if it doesn’t read very well! Thanks to [@collintmiller](http://twitter.com/collintmiller)!
8 changes: 4 additions & 4 deletions src/md/2010-02-15-coerce-equality.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<code>
3 == "3" // true
</code>
``` javascript
3 == "3" // true
```

[@robertnyman](http://twitter.com/robertnyman) reminding us why === is a best practice.
[@robertnyman](http://twitter.com/robertnyman) reminding us why === is a best practice.
4 changes: 2 additions & 2 deletions src/md/2010-02-15-firebug-reserved.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
```
``` javascript
// whilst in firebug, try:
var console = {}; // or, well - anything actually...
```

Firebug absolutely won’t let you create a variable called console, try and it’ll kick you in the happy sack - [@rem](http://twitter.com/rem)
Firebug absolutely won’t let you create a variable called console, try and it’ll kick you in the happy sack - [@rem](http://twitter.com/rem)
4 changes: 2 additions & 2 deletions src/md/2010-02-15-hoisting.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
```
``` javascript
(function(){
alert(window); // "undefined"
var window = window;
})();
```

Because of “hoisting”, all variable *declarations* will be executed immediately at the top of a function scope. However, the variable *initializations* are not hoisted. So, local variable “window” is declared but uninitialized/”undefined”. wt-fun!
Because of “hoisting”, all variable *declarations* will be executed immediately at the top of a function scope. However, the variable *initializations* are not hoisted. So, local variable “window” is declared but uninitialized/”undefined”. wt-fun!
8 changes: 4 additions & 4 deletions src/md/2010-02-15-more-coerce-fun.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<code>
3 == "03" // true!
</code>
``` javascript
3 == "03" // true!
```

[@dandean](http://twitter.com/dandean) tweets, Don’t mind that zero there. I’m _sure_ it’s not important.

Bwahahaha!
Bwahahaha!
4 changes: 2 additions & 2 deletions src/md/2010-02-15-scope-fun.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[@kriskowal](http://twitter.com/kriskowal), of [CommonJS](http://commonjs.org) fame, points out lexical scoping could solve this issue. Ah, JavaScript you are a dirty little language. Dirty dirty…slut! Ya you like those global variables… aaaaaw yah…

```
``` javascript
Object.prototype.foo = 10;
console.log(foo); // 10
```
```
4 changes: 2 additions & 2 deletions src/md/2010-02-15-thc-timetravel.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

Woah!

```
``` javascript
var bignum = 1e300;
var ∞ = 1e400; //Infinity
alert(∞ - bignum); //Infinity
```

Also note: [@sh1mmer](http://twitter.com/sh1mmer) is from the future wherein Unicode entities are valid for variable identifiers. Rename above to something sane in our old school present day interpreters.
Also note: [@sh1mmer](http://twitter.com/sh1mmer) is from the future wherein Unicode entities are valid for variable identifiers. Rename above to something sane in our old school present day interpreters.
4 changes: 2 additions & 2 deletions src/md/2010-02-15-timeout-delay.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
For Firefox only, any function executed by a setTimeout or setInterval invocation will get passed to it (whether you want it to or not) a mysterious “lateness” variable, which represents the number of milliseconds late the function is in executing. Sucks because it can clobber an intentionally unpassed “default” variable to your function. Sucks even more if this variable is intended to be boolean, because you end up with ”random” true/false’y values.

```
``` javascript
// for FF only
setTimeout(function(rand){ alert(rand); },10); // FF passes a "magic" param we call "rand"
for (var i=0; i<100000; i++) { i; } // take some time
```
```
4 changes: 2 additions & 2 deletions src/md/2010-02-15-true-has-a-value.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[@AtomFusion](http://twitter.com/AtomFusion) shows us that true sometimes has a value.

```
``` javascript
(true + 1) === 2;​ ​// true
(true + true) === 2; // true
true === 2; // false
true === 1; // false
```

Wow wtf.
Wow wtf.
6 changes: 3 additions & 3 deletions src/md/2010-02-15-undefined-is-mutable.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
In JavaScript, undefined is nothing but a global variable name without a default value. Therefore, its primitive value is undefined. You can change the value of undefined:

```
``` javascript
var a = {};
a.b === undefined; // true because property b is not set
undefined = 42;
Expand All @@ -9,9 +9,9 @@ In JavaScript, undefined is nothing but a global variable name without a default

Due to the mutability of undefined, it is generally a better idea to check for undefined-ness through typeof:

```
``` javascript
var a = {};
typeof a.b == 'undefined'; // always true
```

– [@mathias](http://mathiasbynens.be/)
– [@mathias](http://mathiasbynens.be/)
4 changes: 2 additions & 2 deletions src/md/2010-02-16-automagic-semicolons.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
I’m certain that this will end all debate about where curly braces belong… right?

```
``` javascript
function laugh()
{
return
Expand All @@ -10,4 +10,4 @@ I’m certain that this will end all debate about where curly braces belong… r
}
laugh();
// returns undefined
```
```
4 changes: 2 additions & 2 deletions src/md/2010-02-16-more-floating-point-rounding.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
In my quest to find whether Infinity was a finite number, I found this. Two numbers that are different are the exact same. - [@rem](http://twitter.com/rem)

```
``` javascript
// note the number to the left of the 'e', 7 and 8 respectively
alert( 1.7976931348623157e+308 === 1.7976931348623158e+308 ); // true!
```
```
4 changes: 2 additions & 2 deletions src/md/2010-02-16-reserved-for-future-use-maybe.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
JavaScript has a [ludicrous list of reserved words](https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Reserved_Words); most of them aren’t even used as keywords in the language. Modern browsers allow using most of these words as identifiers, despite what the spec says. But Safari doesn’t like enum for some reason.

```
``` javascript
// In Safari, try...
var enum;
//-> SyntaxError: Parse error
```
```
4 changes: 2 additions & 2 deletions src/md/2010-02-19-concat-coerce.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
More concat “fun”.

```
``` javascript
"3" + 1 // '31'
"3" - 1 // 2
"222" - -"111" // 333 (⊙﹏⊙)
```
```
6 changes: 3 additions & 3 deletions src/md/2010-02-23-arguing-with-arguments.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Nice arguments hackery going on here.

```
``` javascript
(function(a,b,c) {
print(a,b,c); // one two three
print(arguments[0], arguments[1], arguments[2]); // one two three
Expand All @@ -20,7 +20,7 @@ Nice arguments hackery going on here.
}
```

```
``` javascript
// A more real world example:
(function(arg1, arg2) {
print(arg1, arg2);
Expand All @@ -31,4 +31,4 @@ Nice arguments hackery going on here.
})('uno', 'dos');
```

Thanks to [@deadlyicon](http://twitter.com/deadlyicon)!
Thanks to [@deadlyicon](http://twitter.com/deadlyicon)!
4 changes: 2 additions & 2 deletions src/md/2010-02-23-boolean-paradox.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Boolean logic paradox via [@amattie](amattie)!

```
``` javascript
"0" && {} // true
0 && {} // false, ok...fair enough
0 == "0" // true, wtf!
```
```
4 changes: 2 additions & 2 deletions src/md/2010-02-23-coerced.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Careful w/ number type coercion! Thanks [@kelemen_viktor](http://twitter.com/kelemen_viktor)!

<code>
``` javascript
a = 012 // 10
</code>
```
4 changes: 2 additions & 2 deletions src/md/2010-02-23-declaration-vs-initialization.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
```
``` javascript
var a = 8;
var someFunc = function(){
document.write(a);
Expand All @@ -7,4 +7,4 @@
someFunc(); // writes undefined
```

Of course, the variable is undefined because its being declared but not initialized until after the document.write in the function context which itself runs before the first declaration of a. Yowza. Cheers to [Boaz, Al & Rick](http://weblog.bocoup.com/weird-var-behavior-in-javascript) for this one!
Of course, the variable is undefined because its being declared but not initialized until after the document.write in the function context which itself runs before the first declaration of a. Yowza. Cheers to [Boaz, Al & Rick](http://weblog.bocoup.com/weird-var-behavior-in-javascript) for this one!
Loading