diff --git a/src/shared/md/2010-02-12-almost-but-not-quite.md b/src/shared/md/2010-02-12-almost-but-not-quite.md
index 4ec7790..6a35717 100644
--- a/src/shared/md/2010-02-12-almost-but-not-quite.md
+++ b/src/shared/md/2010-02-12-almost-but-not-quite.md
@@ -1,3 +1,3 @@
-
+
\ No newline at end of file
+
diff --git a/src/shared/md/2010-02-12-foonanny.md b/src/shared/md/2010-02-12-foonanny.md
index 6c98ce1..1eb8c92 100644
--- a/src/shared/md/2010-02-12-foonanny.md
+++ b/src/shared/md/2010-02-12-foonanny.md
@@ -2,9 +2,9 @@ Evaluted as `"foo" + (+ "bar")`, which converts “bar” to not a number.
Proposal to rename this site: NaNwtf
-
alert(111111111111111111111); // alerts 111111111111111110000
-
+
+
**Explanation**
1. `+"bar"` calls `"bar".valueOf()` which tries to return a number
diff --git a/src/shared/md/2010-02-12-function-context-fun.md b/src/shared/md/2010-02-12-function-context-fun.md
index dea0f16..e495e20 100644
--- a/src/shared/md/2010-02-12-function-context-fun.md
+++ b/src/shared/md/2010-02-12-function-context-fun.md
@@ -1,6 +1,6 @@
-
("foo" + + "bar") === "fooNaN" // true
-
+
+
- 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
diff --git a/src/shared/md/2010-02-12-maths-fun.md b/src/shared/md/2010-02-12-maths-fun.md
index 456c4a8..7b15d23 100644
--- a/src/shared/md/2010-02-12-maths-fun.md
+++ b/src/shared/md/2010-02-12-maths-fun.md
@@ -1,7 +1,7 @@
Clearly JavaScript is not the most beautiful, or intuitive, language for maths.
-```
+
(x=[].reverse)() === window // true
-
typeof NaN === 'number' // true
Infinity === 1/0 // true
0.1 + 0.2 === 0.3 // false
-```
\ No newline at end of file
+
diff --git a/src/shared/md/2010-02-12-min-number-treachery.md b/src/shared/md/2010-02-12-min-number-treachery.md
index c3ad0f0..111d81d 100644
--- a/src/shared/md/2010-02-12-min-number-treachery.md
+++ b/src/shared/md/2010-02-12-min-number-treachery.md
@@ -1,6 +1,6 @@
-
+
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.
\ No newline at end of file
+It turns out that MIN_VALUE is the smallest number GREATER THAN ZERO, which of course totally makes sense.
diff --git a/src/shared/md/2010-02-12-not-a-number-is-a-number.md b/src/shared/md/2010-02-12-not-a-number-is-a-number.md
index 35502ef..9996e06 100644
--- a/src/shared/md/2010-02-12-not-a-number-is-a-number.md
+++ b/src/shared/md/2010-02-12-not-a-number-is-a-number.md
@@ -1,5 +1,5 @@
-
+
typeof NaN // number, of course.
-
+
-Now that makes sense.
\ No newline at end of file
+Now that makes sense.
diff --git a/src/shared/md/2010-02-12-not-a-number-is-not-a-not-a-number.md b/src/shared/md/2010-02-12-not-a-number-is-not-a-not-a-number.md
index ed5d517..ea43a8b 100644
--- a/src/shared/md/2010-02-12-not-a-number-is-not-a-not-a-number.md
+++ b/src/shared/md/2010-02-12-not-a-number-is-not-a-not-a-number.md
@@ -1,5 +1,5 @@
Some argue this makes sense. Some ppl also like to sniff glue.
-
+
NaN === NaN // false
-
\ No newline at end of file
+
diff --git a/src/shared/md/2010-02-12-null-is-not-an-object.md b/src/shared/md/2010-02-12-null-is-not-an-object.md
index b2baef9..64e3e29 100644
--- a/src/shared/md/2010-02-12-null-is-not-an-object.md
+++ b/src/shared/md/2010-02-12-null-is-not-an-object.md
@@ -1,6 +1,6 @@
-```
+
typeof null // object
null instanceof Object // false
-```
+
-Classic null is not an Object.
\ No newline at end of file
+Classic null is not an Object.
diff --git a/src/shared/md/2010-02-12-parseint-treachery.md b/src/shared/md/2010-02-12-parseint-treachery.md
index b67a69c..defa732 100644
--- a/src/shared/md/2010-02-12-parseint-treachery.md
+++ b/src/shared/md/2010-02-12-parseint-treachery.md
@@ -1,6 +1,6 @@
-```
+
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.
\ No newline at end of file
+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.
diff --git a/src/shared/md/2010-02-13-null-is-not-falsy.md b/src/shared/md/2010-02-13-null-is-not-falsy.md
index 1b729bf..994fc75 100644
--- a/src/shared/md/2010-02-13-null-is-not-falsy.md
+++ b/src/shared/md/2010-02-13-null-is-not-falsy.md
@@ -1,5 +1,5 @@
-```
+
[] == false; // true
"" == false; // true
null == false; // false, that's more like it
-```
\ No newline at end of file
+
diff --git a/src/shared/md/2010-02-13-string-is-not-string.md b/src/shared/md/2010-02-13-string-is-not-string.md
index 8fd80e5..20c7ad6 100644
--- a/src/shared/md/2010-02-13-string-is-not-string.md
+++ b/src/shared/md/2010-02-13-string-is-not-string.md
@@ -1,7 +1,7 @@
-```
- "string" instanceof String; // false.
+
+ "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)
\ No newline at end of file
+When is a string, not a string? When it’s a duck - [@rem](http://twitter.com/rem)
diff --git a/src/shared/md/2010-02-15-accidental-global.md b/src/shared/md/2010-02-15-accidental-global.md
index 91de46f..7417031 100644
--- a/src/shared/md/2010-02-15-accidental-global.md
+++ b/src/shared/md/2010-02-15-accidental-global.md
@@ -1,11 +1,11 @@
-This one is fun and sneaky.
+This one is fun and sneaky.
-```
+
(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”.
\ No newline at end of file
+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”.
diff --git a/src/shared/md/2010-02-15-careful.md b/src/shared/md/2010-02-15-careful.md
index 57ab0fb..ae36e33 100644
--- a/src/shared/md/2010-02-15-careful.md
+++ b/src/shared/md/2010-02-15-careful.md
@@ -1,5 +1,5 @@
-
+
[] == ![] // 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)!
\ No newline at end of file
+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)!
diff --git a/src/shared/md/2010-02-15-coerce-equality.md b/src/shared/md/2010-02-15-coerce-equality.md
index 3637924..277154b 100644
--- a/src/shared/md/2010-02-15-coerce-equality.md
+++ b/src/shared/md/2010-02-15-coerce-equality.md
@@ -1,5 +1,5 @@
-
+
3 == "3" // true
-
+
-[@robertnyman](http://twitter.com/robertnyman) reminding us why === is a best practice.
\ No newline at end of file
+[@robertnyman](http://twitter.com/robertnyman) reminding us why === is a best practice.
diff --git a/src/shared/md/2010-02-15-firebug-reserved.md b/src/shared/md/2010-02-15-firebug-reserved.md
index 02098d4..a877c66 100644
--- a/src/shared/md/2010-02-15-firebug-reserved.md
+++ b/src/shared/md/2010-02-15-firebug-reserved.md
@@ -1,6 +1,6 @@
-```
+
// 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)
\ No newline at end of file
+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)
diff --git a/src/shared/md/2010-02-15-hoisting.md b/src/shared/md/2010-02-15-hoisting.md
index d8fee4e..2fc94e4 100644
--- a/src/shared/md/2010-02-15-hoisting.md
+++ b/src/shared/md/2010-02-15-hoisting.md
@@ -1,8 +1,8 @@
-```
+
(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!
\ No newline at end of file
+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!
diff --git a/src/shared/md/2010-02-15-more-coerce-fun.md b/src/shared/md/2010-02-15-more-coerce-fun.md
index eabca80..3dced59 100644
--- a/src/shared/md/2010-02-15-more-coerce-fun.md
+++ b/src/shared/md/2010-02-15-more-coerce-fun.md
@@ -1,7 +1,7 @@
-
+
3 == "03" // true!
-
+
[@dandean](http://twitter.com/dandean) tweets, Don’t mind that zero there. I’m _sure_ it’s not important.
-Bwahahaha!
\ No newline at end of file
+Bwahahaha!
diff --git a/src/shared/md/2010-02-15-scope-fun.md b/src/shared/md/2010-02-15-scope-fun.md
index 30a7f91..61533c4 100644
--- a/src/shared/md/2010-02-15-scope-fun.md
+++ b/src/shared/md/2010-02-15-scope-fun.md
@@ -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…
-```
- Object.prototype.foo = 10;
+
+ Object.prototype.foo = 10;
console.log(foo); // 10
-```
\ No newline at end of file
+
diff --git a/src/shared/md/2010-02-15-thc-timetravel.md b/src/shared/md/2010-02-15-thc-timetravel.md
index c9008f7..b01a031 100644
--- a/src/shared/md/2010-02-15-thc-timetravel.md
+++ b/src/shared/md/2010-02-15-thc-timetravel.md
@@ -2,10 +2,10 @@
Woah!
-```
+
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.
\ No newline at end of file
+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.
diff --git a/src/shared/md/2010-02-15-timeout-delay.md b/src/shared/md/2010-02-15-timeout-delay.md
index 9b824ae..3df6982 100644
--- a/src/shared/md/2010-02-15-timeout-delay.md
+++ b/src/shared/md/2010-02-15-timeout-delay.md
@@ -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.
-```
+
// 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
-```
\ No newline at end of file
+
diff --git a/src/shared/md/2010-02-15-true-has-a-value.md b/src/shared/md/2010-02-15-true-has-a-value.md
index 3a39f62..2d9bfb7 100644
--- a/src/shared/md/2010-02-15-true-has-a-value.md
+++ b/src/shared/md/2010-02-15-true-has-a-value.md
@@ -1,10 +1,10 @@
[@AtomFusion](http://twitter.com/AtomFusion) shows us that true sometimes has a value.
-```
+
(true + 1) === 2; // true
(true + true) === 2; // true
true === 2; // false
true === 1; // false
-```
+
-Wow wtf.
\ No newline at end of file
+Wow wtf.
diff --git a/src/shared/md/2010-02-15-undefined-is-mutable.md b/src/shared/md/2010-02-15-undefined-is-mutable.md
index 19baacf..3f3c69e 100644
--- a/src/shared/md/2010-02-15-undefined-is-mutable.md
+++ b/src/shared/md/2010-02-15-undefined-is-mutable.md
@@ -1,17 +1,17 @@
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:
-```
+
var a = {};
a.b === undefined; // true because property b is not set
undefined = 42;
a.b === undefined; // false
-```
+
Due to the mutability of undefined, it is generally a better idea to check for undefined-ness through typeof:
-```
+
var a = {};
typeof a.b == 'undefined'; // always true
-```
+
-– [@mathias](http://mathiasbynens.be/)
\ No newline at end of file
+– [@mathias](http://mathiasbynens.be/)
diff --git a/src/shared/md/2010-02-16-automagic-semicolons.md b/src/shared/md/2010-02-16-automagic-semicolons.md
index 24b6de7..334e79a 100644
--- a/src/shared/md/2010-02-16-automagic-semicolons.md
+++ b/src/shared/md/2010-02-16-automagic-semicolons.md
@@ -1,6 +1,6 @@
I’m certain that this will end all debate about where curly braces belong… right?
-```
+
function laugh()
{
return
@@ -10,6 +10,6 @@ I’m certain that this will end all debate about where curly braces belong… r
}
laugh();
// returns undefined
-```
+
See also: [Automatic semicolon insertion](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Automatic_semicolon_insertion)
diff --git a/src/shared/md/2010-02-16-more-floating-point-rounding.md b/src/shared/md/2010-02-16-more-floating-point-rounding.md
index 1a1a924..fe07bce 100644
--- a/src/shared/md/2010-02-16-more-floating-point-rounding.md
+++ b/src/shared/md/2010-02-16-more-floating-point-rounding.md
@@ -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)
-```
+
// note the number to the left of the 'e', 7 and 8 respectively
alert( 1.7976931348623157e+308 === 1.7976931348623158e+308 ); // true!
-```
\ No newline at end of file
+
diff --git a/src/shared/md/2010-02-16-reserved-for-future-use-maybe.md b/src/shared/md/2010-02-16-reserved-for-future-use-maybe.md
index bd93136..f74987d 100644
--- a/src/shared/md/2010-02-16-reserved-for-future-use-maybe.md
+++ b/src/shared/md/2010-02-16-reserved-for-future-use-maybe.md
@@ -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.
-```
+
// In Safari, try...
var enum;
//-> SyntaxError: Parse error
-```
\ No newline at end of file
+
diff --git a/src/shared/md/2010-02-19-concat-coerce.md b/src/shared/md/2010-02-19-concat-coerce.md
index 323c769..19434ed 100644
--- a/src/shared/md/2010-02-19-concat-coerce.md
+++ b/src/shared/md/2010-02-19-concat-coerce.md
@@ -1,7 +1,7 @@
More concat “fun”.
-```
+
"3" + 1 // '31'
"3" - 1 // 2
"222" - -"111" // 333 (⊙﹏⊙)
-```
\ No newline at end of file
+
diff --git a/src/shared/md/2010-02-23-arguing-with-arguments.md b/src/shared/md/2010-02-23-arguing-with-arguments.md
index d94eece..f4db892 100644
--- a/src/shared/md/2010-02-23-arguing-with-arguments.md
+++ b/src/shared/md/2010-02-23-arguing-with-arguments.md
@@ -1,6 +1,6 @@
-Nice arguments hackery going on here.
+Nice arguments hackery going on here.
-```
+
(function(a,b,c) {
print(a,b,c); // one two three
print(arguments[0], arguments[1], arguments[2]); // one two three
@@ -18,9 +18,9 @@ Nice arguments hackery going on here.
args[1] = "up your";
args[2] = "dataz";
}
-```
-
-```
+
+
+
// A more real world example:
(function(arg1, arg2) {
print(arg1, arg2);
@@ -29,6 +29,6 @@ Nice arguments hackery going on here.
print(arg1, arg2);
//-> dose undefined
})('uno', 'dos');
-```
+
-Thanks to [@deadlyicon](http://twitter.com/deadlyicon)!
\ No newline at end of file
+Thanks to [@deadlyicon](http://twitter.com/deadlyicon)!
diff --git a/src/shared/md/2010-02-23-boolean-paradox.md b/src/shared/md/2010-02-23-boolean-paradox.md
index 7cfef38..4e9a3ae 100644
--- a/src/shared/md/2010-02-23-boolean-paradox.md
+++ b/src/shared/md/2010-02-23-boolean-paradox.md
@@ -1,7 +1,7 @@
Boolean logic paradox via [@amattie](amattie)!
-```
+
"0" && {} // true
0 && {} // false, ok...fair enough
0 == "0" // true, wtf!
-```
\ No newline at end of file
+
diff --git a/src/shared/md/2010-02-23-coerced.md b/src/shared/md/2010-02-23-coerced.md
index b14d3ca..46aa668 100644
--- a/src/shared/md/2010-02-23-coerced.md
+++ b/src/shared/md/2010-02-23-coerced.md
@@ -1,7 +1,7 @@
Careful w/ number type coercion! Thanks [@kelemen_viktor](http://twitter.com/kelemen_viktor)!
-
+
a = 012 // 10
-
+
That's why JavaScript assumes (for whatever reason) that the number is octal (e. g. `parseInt('012', 8)`).
diff --git a/src/shared/md/2010-02-23-declaration-vs-initialization.md b/src/shared/md/2010-02-23-declaration-vs-initialization.md
index a3cbbc3..d1f0179 100644
--- a/src/shared/md/2010-02-23-declaration-vs-initialization.md
+++ b/src/shared/md/2010-02-23-declaration-vs-initialization.md
@@ -1,10 +1,10 @@
-```
+
var a = 8;
var someFunc = function(){
document.write(a);
var a = 8;
};
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!
\ No newline at end of file
+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!
diff --git a/src/shared/md/2010-02-23-makes-perfect-sense.md b/src/shared/md/2010-02-23-makes-perfect-sense.md
index 4d9e564..d5ce655 100644
--- a/src/shared/md/2010-02-23-makes-perfect-sense.md
+++ b/src/shared/md/2010-02-23-makes-perfect-sense.md
@@ -1,7 +1,7 @@
-Ha! This one is great.
+Ha! This one is great.
-
+
3 > 2 > 1 // false
-
+
-Remember how [true sometimes has a value](https://wtfjs.com/wtfs/2010-02-15-true-has-a-value) so in the above 3 > 2 evaluates to true making the second part of the expression evaluate true > 1 which is false. Of course! Thanks to [void_0](http://twitter.com/void_0) for this one!
\ No newline at end of file
+Remember how [true sometimes has a value](https://wtfjs.com/wtfs/2010-02-15-true-has-a-value) so in the above 3 > 2 evaluates to true making the second part of the expression evaluate true > 1 which is false. Of course! Thanks to [void_0](http://twitter.com/void_0) for this one!
diff --git a/src/shared/md/2010-02-24-messing-with-number-prototype.md b/src/shared/md/2010-02-24-messing-with-number-prototype.md
index b8b5b12..d122b73 100644
--- a/src/shared/md/2010-02-24-messing-with-number-prototype.md
+++ b/src/shared/md/2010-02-24-messing-with-number-prototype.md
@@ -1,13 +1,13 @@
[@rcanine](http://twitter.com/rcanine) shows us this interesting this coerce behaviour within the prototype of Number. Fun!
-```
+
(1) === 1; // true
-
+
Number.prototype.isOne = function () { return this === 1; }
-
+
(1).isOne(); // false!
-
+
Number.prototype.reallyIsOne = function () { return this - 1 === 0; }
-
+
(1).reallyIsOne(); // true
-```
\ No newline at end of file
+
diff --git a/src/shared/md/2010-02-25-ie-and-webkit-agree.md b/src/shared/md/2010-02-25-ie-and-webkit-agree.md
index 019a334..73e81a9 100644
--- a/src/shared/md/2010-02-25-ie-and-webkit-agree.md
+++ b/src/shared/md/2010-02-25-ie-and-webkit-agree.md
@@ -1,5 +1,5 @@
Interesting how IE and WebKit treat this differently than Firefox and Opera. Some sort of pre-compilation going on? Who knows. Thanks [@jeronevw](http://twitter.com/jeronevw)!
-```
+
(function(){return 2*3;}).toString() === (function(){return 6;}).toString(); // true in FF & Opera, false in IE & WebKit
-```
\ No newline at end of file
+
diff --git a/src/shared/md/2010-02-25-ie-scope.md b/src/shared/md/2010-02-25-ie-scope.md
index 23a99d1..a9eaefb 100644
--- a/src/shared/md/2010-02-25-ie-scope.md
+++ b/src/shared/md/2010-02-25-ie-scope.md
@@ -1,10 +1,10 @@
[@jaffathecake](http://twitter.com/jaffathecake) has some more fun with IE. As we do.
-```
+
window.window == window // true
window.window === window // false
window == document // true. wtf!
-```
+
[@filmaj](http://twitter.com/filmaj) says, “I think it’s because object equality implicitly calls toString(), and in IE most native DOM objects return just ‘[object]’ in toString(), whereas standard browser return something like ‘[object ClassName]’, which is probably why WebKit doesn’t do the same thing.”
diff --git a/src/shared/md/2010-02-25-jsftw:-google-closure-compiler.md b/src/shared/md/2010-02-25-jsftw:-google-closure-compiler.md
index 1162d47..3e3868a 100644
--- a/src/shared/md/2010-02-25-jsftw:-google-closure-compiler.md
+++ b/src/shared/md/2010-02-25-jsftw:-google-closure-compiler.md
@@ -1,6 +1,6 @@
-
+
// Google closure compiler 1000 to 1E3 - love it!
1000 === 1E3; // true
-
+
-When going through the result of Google’s closure compiler, I found that it had compressed 1000 to 1E3 - brilliant! - [@rem](http://twitter.com/rem)
\ No newline at end of file
+When going through the result of Google’s closure compiler, I found that it had compressed 1000 to 1E3 - brilliant! - [@rem](http://twitter.com/rem)
diff --git a/src/shared/md/2010-02-26-array-crazy.md b/src/shared/md/2010-02-26-array-crazy.md
index 182265d..95ef0f0 100644
--- a/src/shared/md/2010-02-26-array-crazy.md
+++ b/src/shared/md/2010-02-26-array-crazy.md
@@ -1,17 +1,17 @@
Plausible code:
-```
+
[] == 0 // true
+[] === 0 // true, wait whu?
++[] === 1 // sorta, though this is invalid js syntax, so...
-```
+
Somewhat unlikely and, lets be honest, regrettable code:
-```
+
[[]][0] === []
++[[]][0] === 1
++[[]][+[]] === 1 // yay! wtf!
-```
+
[John Resig explains here.](http://news.ycombinator.com/item?id=1154338)
diff --git a/src/shared/md/2010-02-26-implicit-tostring-fun.md b/src/shared/md/2010-02-26-implicit-tostring-fun.md
index c3edc44..d8479c3 100644
--- a/src/shared/md/2010-02-26-implicit-tostring-fun.md
+++ b/src/shared/md/2010-02-26-implicit-tostring-fun.md
@@ -1,17 +1,17 @@
Be careful with those implicit .toString() calls in == comparisons.
-```
+
typeof "abc" == "string" // true
typeof String("abc") == "string" // true
- String("abc") == "abc" // true -- same types get casted to equal each other
-```
+ String("abc") == "abc" // true -- same types get casted to equal each other
+
Also, instantiation via the _new_ operator can yield interesting results!
-```
+
String("abc") instanceof String // false -- hmmm...
(new String("abc")) instanceof String // true
String("abc") == (new String("abc")) // true -- wait, wtf?
-```
+
-As always, we are reminded to test with the strict equality operator: _===_.
\ No newline at end of file
+As always, we are reminded to test with the strict equality operator: _===_.
diff --git a/src/shared/md/2010-03-02-ie-cursed-recursion.md b/src/shared/md/2010-03-02-ie-cursed-recursion.md
index a4668b7..d89082b 100644
--- a/src/shared/md/2010-03-02-ie-cursed-recursion.md
+++ b/src/shared/md/2010-03-02-ie-cursed-recursion.md
@@ -1,10 +1,10 @@
-```
+
window.recurse = function(times) {
if (times !== 0)
recurse(times - 1);
};
recurse(13); // stack overflow at: 0
-```
+
[@tlrobinson](http://twitter.com/tlrobinson) of [280 North](http://280north.com/), [Cappuccino](http://cappuccino.org/), [Narwhal](http://narwhaljs.org/) and [CommonJS](http://commonjs.org/) points out some lovely IE behavior in [this great blog post](http://cappuccino.org/discuss/2010/03/01/internet-explorer-global-variables-and-stack-overflows/).
diff --git a/src/shared/md/2010-03-04-max-vs-the-infinite.md b/src/shared/md/2010-03-04-max-vs-the-infinite.md
index 1de2ef2..6f84a61 100644
--- a/src/shared/md/2010-03-04-max-vs-the-infinite.md
+++ b/src/shared/md/2010-03-04-max-vs-the-infinite.md
@@ -1,7 +1,7 @@
[@pbakaus](http://twitter.com/pbakaus) points out that Number.MAX_VALUE is close to infinity, but not too close.
-```
+
Number.MAX_VALUE*1.0000000000000001 === (1/0) // false
Number.MAX_VALUE*1.0000000000000002 === (1/0) // true
-```
\ No newline at end of file
+
diff --git a/src/shared/md/2010-04-02-object-to-primitive-coerce.md b/src/shared/md/2010-04-02-object-to-primitive-coerce.md
index 98e58d3..890cd73 100644
--- a/src/shared/md/2010-04-02-object-to-primitive-coerce.md
+++ b/src/shared/md/2010-04-02-object-to-primitive-coerce.md
@@ -1,15 +1,15 @@
-```
- var foo = {
- toString: function () {
- return 5;
- },
- valueOf: function () {
- return "foo";
- }
- };
- alert(foo.toString() + 1); // 6 (bad!)
- alert(foo + 1); // "foo1" (no good!)
+
+ var foo = {
+ toString: function () {
+ return 5;
+ },
+ valueOf: function () {
+ return "foo";
+ }
+ };
+ alert(foo.toString() + 1); // 6 (bad!)
+ alert(foo + 1); // "foo1" (no good!)
alert(+foo); // NaN (the worst!)
-```
+
-Thanks to [Ajaxian](http://ajaxian.com/archives/a-very-detailed-look-at-object-to-primitive-conversions) for pointing out this [amazingly detailed look at object to primitive coercion](http://www.adequatelygood.com/2010/3/Object-to-Primitive-Conversions-in-JavaScript).
\ No newline at end of file
+Thanks to [Ajaxian](http://ajaxian.com/archives/a-very-detailed-look-at-object-to-primitive-conversions) for pointing out this [amazingly detailed look at object to primitive coercion](http://www.adequatelygood.com/2010/3/Object-to-Primitive-Conversions-in-JavaScript).
diff --git a/src/shared/md/2010-04-12-call-in-ur-call.md b/src/shared/md/2010-04-12-call-in-ur-call.md
index 5fcd661..41b3972 100644
--- a/src/shared/md/2010-04-12-call-in-ur-call.md
+++ b/src/shared/md/2010-04-12-call-in-ur-call.md
@@ -1,5 +1,5 @@
That must be some good shit [@cramforce](http://twitter.com/cramforce) was smoking when he found this one.
-
+
alert.call.call.call.call.call.apply(function (a) {return a}, [1,2]) // 2
-
\ No newline at end of file
+
diff --git a/src/shared/md/2010-04-16-build-your-own-wtfjs.md b/src/shared/md/2010-04-16-build-your-own-wtfjs.md
index a7fe70a..0116176 100644
--- a/src/shared/md/2010-04-16-build-your-own-wtfjs.md
+++ b/src/shared/md/2010-04-16-build-your-own-wtfjs.md
@@ -1,10 +1,10 @@
-Maybe you want to deploy a code blog quickly. Maybe you want an excuse to play with NodeJS. I don't know what it is you are up to but here's a quick guide to building your own wtfjs. This requires a Heroku NodeJS access, of course.
+Maybe you want to deploy a code blog quickly. Maybe you want an excuse to play with NodeJS. I don't know what it is you are up to but here's a quick guide to building your own wtfjs. This requires a Heroku NodeJS access, of course.
-```
+
$ git clone git@github.com:brianleroux/wtfjs.git
$ cd wtfjs/
- $ heroku create --stack beech
+ $ heroku create --stack beech
$ git push heroku master
-```
+
You're done!
diff --git a/src/shared/md/2010-04-16-express-js-gotcha.md b/src/shared/md/2010-04-16-express-js-gotcha.md
index a966e71..375da4b 100644
--- a/src/shared/md/2010-04-16-express-js-gotcha.md
+++ b/src/shared/md/2010-04-16-express-js-gotcha.md
@@ -1,11 +1,11 @@
Less of a wtf and more of a gotcha. In [ExpressJS](http://expressjs.com/). you can serve static files from a _/public_ directory with this simple directive in your configure block:
-```
+
configure(function() {
- set("root", __dirname);
+ set("root", __dirname);
// allow static file serving from public directory
- use(Static);
+ use(Static);
});
-```
+
-But be careful! This sets a the path to be _/public/app.css_ rather than _/app.css_. [More background here.](http://groups.google.com/group/express-js/browse_thread/thread/863ed1888597e630)
\ No newline at end of file
+But be careful! This sets a the path to be _/public/app.css_ rather than _/app.css_. [More background here.](http://groups.google.com/group/express-js/browse_thread/thread/863ed1888597e630)
diff --git a/src/shared/md/2010-04-16-syntax-highlighting-wtf.md b/src/shared/md/2010-04-16-syntax-highlighting-wtf.md
index 1ea2669..e4b586f 100644
--- a/src/shared/md/2010-04-16-syntax-highlighting-wtf.md
+++ b/src/shared/md/2010-04-16-syntax-highlighting-wtf.md
@@ -1,10 +1,10 @@
Syntax highlighting seems like a solved problem. Over solved. To make matters worse it appears that the production of Sinatra clones and Syntax Highlighters are escalating. Perhaps its a sign.
-After struggling w/ the overly complex Chili jQuery plugin I had a second look at the classic Syntax Highlighter which, while palatable, feels like overkill. Its a bummer b/c I would prefer a highlighter than can deal w/ nested DOM elements. Pygments does all this but Heroku won't let play with the sandbox, and I didn't want to pre-process the markdown treating it like an intermediate format, so I settled on SHJS which has the right characteristics: lightweight, simple install and straightforward docs.
+After struggling w/ the overly complex Chili jQuery plugin I had a second look at the classic Syntax Highlighter which, while palatable, feels like overkill. Its a bummer b/c I would prefer a highlighter than can deal w/ nested DOM elements. Pygments does all this but Heroku won't let play with the sandbox, and I didn't want to pre-process the markdown treating it like an intermediate format, so I settled on SHJS which has the right characteristics: lightweight, simple install and straightforward docs.
Only caveat: it only works on _pre_ tags. Thus:
-```
+
$(function(){
// change code elements into pre elements with class sh_javascript_dom
$('code').each(function(){
@@ -19,8 +19,8 @@ Only caveat: it only works on _pre_ tags. Thus:
// invoke clientside syntax highlighter
sh_highlightDocument();
});
-```
+
Not entirely hideous but plenty to wtf about. Inspect the actual code and compare to the embed above you'll notice I had to swap a nested _pre_ element with a string "pre tag would be here". It gets better: double line breaks mindfuck SHJS forcing it to create new nested pre tags. So no line double breaks. If that wasn't enough all the underscores in the class identifier have been removed. Daaamnit wtf?!
-Problem: unsolved. - brianleroux
\ No newline at end of file
+Problem: unsolved. - brianleroux
diff --git a/src/shared/md/2010-04-17-global-scope-mindtricks.md b/src/shared/md/2010-04-17-global-scope-mindtricks.md
index 4101e38..dd6a407 100644
--- a/src/shared/md/2010-04-17-global-scope-mindtricks.md
+++ b/src/shared/md/2010-04-17-global-scope-mindtricks.md
@@ -2,24 +2,24 @@ An update by [@deadlyicon](http://twitter.com/deadlyicon) on the previous post.
This is just a really silly way of saying this:
-```
+
Function.prototype.call.apply(function (a) {return a}, [1,2])
// 2
-```
+
-If this still seems weird to you. Consider this:
+If this still seems weird to you. Consider this:
-```
- function logThisAndArgs() {
- console.log(this, arguments);
+
+ function logThisAndArgs() {
+ console.log(this, arguments);
};
Function.prototype.call.apply(logThisAndArgs, [{'some':'object'},1,2,3,4])
// logs -> Object { some="object"} [1, 2, 3, 4]
-```
+
-Now this!
+Now this!
-```
+
Function.prototype.call.call(logThisAndArgs, {'some':'object'},1,2,3,4)
// logs -> Object { some="object"} [1, 2, 3, 4]
-```
\ No newline at end of file
+
diff --git a/src/shared/md/2010-04-30-operators-and-regexp-fun.md b/src/shared/md/2010-04-30-operators-and-regexp-fun.md
index a89c796..f5aad13 100644
--- a/src/shared/md/2010-04-30-operators-and-regexp-fun.md
+++ b/src/shared/md/2010-04-30-operators-and-regexp-fun.md
@@ -1,12 +1,12 @@
[@ThomasFuchs](http://twitter.com/thomasfuchs) throws down this obfuscated beauty:
-```
+
1 + + 1 // => 2
1 + - + 1 // => 0
1 + - + - + 1 // => 2
1 + - + - + - + 1 // => 0
1 + - + + + - + 1 // => 2
1 + / + + + / + 1 // => 1/ + + + /1
-```
+
-[Be sure to read the comments!](http://mir.aculo.us/2010/05/28/valid-javascript-or-not/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed:+miraculous+(mir.aculo.us))
\ No newline at end of file
+[Be sure to read the comments!](http://mir.aculo.us/2010/05/28/valid-javascript-or-not/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed:+miraculous+(mir.aculo.us))
diff --git a/src/shared/md/2010-04-31-isNaN.md b/src/shared/md/2010-04-31-isNaN.md
index dfb92b8..96f2173 100644
--- a/src/shared/md/2010-04-31-isNaN.md
+++ b/src/shared/md/2010-04-31-isNaN.md
@@ -1,16 +1,15 @@
So, [null is not an object](https://wtfjs.com/wtfs/2010-02-12-null-is-not-an-object) though sometimes null is a Number.
-```
+
isNaN( null ); // false
null === NaN; // false
null == NaN; // false
-```
+
isNaN converts null to number.
-
+
Number( null ); // 0
-
+
But WTF. :) - [@oleg008](http://twitter.com/oleg008)
-
\ No newline at end of file
diff --git a/src/shared/md/2010-04-31-syntax-highlighting-serverside-with-google-prettyfy.md b/src/shared/md/2010-04-31-syntax-highlighting-serverside-with-google-prettyfy.md
index 6b7de2a..46a7dd8 100644
--- a/src/shared/md/2010-04-31-syntax-highlighting-serverside-with-google-prettyfy.md
+++ b/src/shared/md/2010-04-31-syntax-highlighting-serverside-with-google-prettyfy.md
@@ -1,12 +1,12 @@
This is much more awesome. I have to thank the guys at [HowToNode.org](http://howtonode.org) for the idea in their [WheatJS](http://github.com/creationix/wheat) static site blog engine. Essentially, it all boils down to running the rather awesome [Google Code Prettyfy](http://code.google.com/p/google-code-prettify/) _serverside_.
-The only remaining problem with the syntax highlighting is now nested <code> elements have to be escaped to display correctly in the final render.
+The only remaining problem with the syntax highlighting is now nested <code> elements have to be escaped to display correctly in the final render.
-```
+
// replace the raw code blocks with prettyfied html
t = t.replace(/<code>[^<]+<\/code>/g, function(code) {
return prettyfy(code.match(/<code>([\s\S]+)<\/code>/)[1]);
- });
-```
+ });
+
-Perhaps, in the future, a quick routine to fetch only the root code elements rather than blinding fetching all of them. Problem: more solved than before!
\ No newline at end of file
+Perhaps, in the future, a quick routine to fetch only the root code elements rather than blinding fetching all of them. Problem: more solved than before!
diff --git a/src/shared/md/2010-06-02-instances-and-default-values.md b/src/shared/md/2010-06-02-instances-and-default-values.md
index 4edebf2..1732988 100644
--- a/src/shared/md/2010-06-02-instances-and-default-values.md
+++ b/src/shared/md/2010-06-02-instances-and-default-values.md
@@ -1,6 +1,6 @@
When you create instances of `String` or `Number`, they take the default value (`""` for strings and `0` for numbers). This is not the same for `Object` and `Array`.
-```
+
var a = new Number;
a == 0 // true
@@ -12,18 +12,18 @@ When you create instances of `String` or `Number`, they take the default value (
var a = new Array;
a == [] // false
-```
+
This is even more confusing when using the JSON-style syntax to create objects and arrays.
-```
+
var a = {};
a == {} // false
var a = [];
a == [] // false
-```
+
-- [@remi](http://twitter.com/remi)
-(Never forget: [====](http://crockfordfacts.com/MHDTvKwy3xGzI183Akuh_Q) - [@brianleroux](http://twitter.com/brianleroux))
\ No newline at end of file
+(Never forget: [====](http://crockfordfacts.com/MHDTvKwy3xGzI183Akuh_Q) - [@brianleroux](http://twitter.com/brianleroux))
diff --git a/src/shared/md/2010-06-08-void-is-a-black-hole.md b/src/shared/md/2010-06-08-void-is-a-black-hole.md
index cc631a9..074123e 100644
--- a/src/shared/md/2010-06-08-void-is-a-black-hole.md
+++ b/src/shared/md/2010-06-08-void-is-a-black-hole.md
@@ -1,8 +1,8 @@
Void is a blackhole...
-```
+
var void = function () {}
//=> SyntaxError: missing variable name
-```
+
--- [@rwaldron](http://twitter.com/rwaldron)
\ No newline at end of file
+-- [@rwaldron](http://twitter.com/rwaldron)
diff --git a/src/shared/md/2010-06-09-function-in-ur-string.md b/src/shared/md/2010-06-09-function-in-ur-string.md
index b64d9db..a6809af 100644
--- a/src/shared/md/2010-06-09-function-in-ur-string.md
+++ b/src/shared/md/2010-06-09-function-in-ur-string.md
@@ -1,28 +1,28 @@
Old friend (_and clearly damaged by a career of JavaScript programming_) [@jakedevine](http://twitter.com/jakedevine) threw this down on twitter a few days ago.
-```
- var Z = "constructor";
+
+ var Z = "constructor";
Z[Z][Z]("alert('wtfjs!')")();
// alerts wtfjs!
-```
+
Ok. So wtf exactly is happening here?
-```
+
Z[Z]
// function String() { [native code] }
Z[Z][Z]
// function Function() { [native code] }
-```
+
AHA! The constructor property of a string is `String` and the constructor property of `String` is `Function`. Makes sense.
-```
+
Z[Z][Z]("console.log('new Function accepts string for eval as argument')")();
// new Function accepts string for eval as argument
-```
+
Of course. One wonders, as usual, wtf the programmer was up to when he discovered this!
---- [@brianleroux](http://twitter.com/brianleroux)
\ No newline at end of file
+--- [@brianleroux](http://twitter.com/brianleroux)
diff --git a/src/shared/md/2010-07-11-length-of-what-now.md b/src/shared/md/2010-07-11-length-of-what-now.md
index d19ca0b..cba7560 100644
--- a/src/shared/md/2010-07-11-length-of-what-now.md
+++ b/src/shared/md/2010-07-11-length-of-what-now.md
@@ -1,16 +1,16 @@
This made me laugh. Out loud even!
-```
+
console.log((!+[]+[]+![]).length);
// 9
-```
+
Huh, wtf?! Lets see what we're getting the length of...
-```
+
console.log((!+[]+[]+![]));
// "truefalse"
-```
+
Ah! lulz. thanks to @stepiiik and @DavidGrudl!
diff --git a/src/shared/md/2010-07-12-fail.md b/src/shared/md/2010-07-12-fail.md
index 9cde443..1e73ea5 100644
--- a/src/shared/md/2010-07-12-fail.md
+++ b/src/shared/md/2010-07-12-fail.md
@@ -1,32 +1,32 @@
Let's take the last post a step further:
-```
+
console.log( (![]+[])[+[]]+(![]+[])[+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]] ) // "fail"
-```
+
Breaking that mass of symbols into pieces we notices, that the following patten occurs often:
-```
+
console.log( (![]+[]) ) // "false"
console.log( ![] ) // false
-```
+
So we try adding `[]` to `false`. But through a number of internal function calls( `binary + Operator` -> `ToPrimitive` -> `[[DefaultValue]]`) we end up with converting the right operand to a String:
-```
+
console.log( [].toString() ) // ""
console.log( (![]+[].toString()) ) // false + ""
-```
+
Aha, so we are concatenating strings here! Now this is plain obvious! Moving on to the next bit:
-```
+
console.log( [+[]] ) // [ 0]
console.log( +[] ) // 0
-```
+
Thinking of a `String` as an `Array` we can access its first character via `[0]`. So `"false"[0]` returns `"f"`.
I think you got the idea now and can figure out the rest by yourself!
-Thanks to Mathias Bynens for pushing this out int the web.
\ No newline at end of file
+Thanks to Mathias Bynens for pushing this out int the web.
diff --git a/src/shared/md/2010-07-15-typeof-number-is-not-number.md b/src/shared/md/2010-07-15-typeof-number-is-not-number.md
index 9fb0af2..90bdf9c 100644
--- a/src/shared/md/2010-07-15-typeof-number-is-not-number.md
+++ b/src/shared/md/2010-07-15-typeof-number-is-not-number.md
@@ -1,42 +1,42 @@
How do you determine if a number is an integer in JavaScript?
-```
+
x = 1;
-
+
x === Math.floor(x);
// returns true
-```
+
But what happens if we try to add a method for this to the Number prototype?
-```
+
Number.prototype.isInteger = function() {
return this === Math.floor(this);
}
-
+
x = 1;
-
+
x.isInteger();
// returns false!
-```
+
Why? It turns out that when you add methods to Number, the type of the number inside the method becomes "object" rather than "number", but Math.floor returns a result of type "number". If you use the === operator, the two values are no longer equal because they're different types. So the method can be fixed two ways.
Solution 1 is to avoid comparing types:
-```
+
Number.prototype.isInteger = function() {
return this == Math.floor(this);
// works but breaks if you care about 0 vs other falsy values
}
-```
+
Solution 2 is better; cast "this" to the Number type and then the types are equal.
-```
+
Number.prototype.isInteger = function() {
return Number(this) === Math.floor(this);
}
-```
+
--- [@attaboy](http://twitter.com/attaboy)
diff --git a/src/shared/md/2010-07-22-magic-increasing-number.md b/src/shared/md/2010-07-22-magic-increasing-number.md
index c219169..e3951c8 100644
--- a/src/shared/md/2010-07-22-magic-increasing-number.md
+++ b/src/shared/md/2010-07-22-magic-increasing-number.md
@@ -1,9 +1,9 @@
Look at me, I'm the magic increasing number!
-```
+
9999999999999999
//=> 10000000000000000
-```
+
--- [@thomasfuchs](http://twitter.com/thomasfuchs)
diff --git a/src/shared/md/2010-07-23-im-not-a-number-really.md b/src/shared/md/2010-07-23-im-not-a-number-really.md
index 283cb25..2e0a587 100644
--- a/src/shared/md/2010-07-23-im-not-a-number-really.md
+++ b/src/shared/md/2010-07-23-im-not-a-number-really.md
@@ -1,20 +1,20 @@
You've probably seen this one here before. NaN (**N**ot **a** **N**umber) suffers from a terrible case of self-deception.
-
+
typeof NaN
//=> number
-
+
--- [@3rdEden](http://twitter.com/3rdEden)
Its still hilarious. Now, check this out:
-
+
3..toString();
// "3"
-
+
[Explanation here.](http://stackoverflow.com/questions/1995113/strangest-language-feature/3297392#3297392)
-(By way of the wtfjs twitter firehouse. Cheers: [@devongovett](http://twitter.com/devongovett), [@getify](http://twitter.com/getify), [@mahemoff](http://twitter.com/mahemoff), [@cramforce](http://twitter.com/cramforce), [@mathias](http://twitter.com/mathias)!)
\ No newline at end of file
+(By way of the wtfjs twitter firehouse. Cheers: [@devongovett](http://twitter.com/devongovett), [@getify](http://twitter.com/getify), [@mahemoff](http://twitter.com/mahemoff), [@cramforce](http://twitter.com/cramforce), [@mathias](http://twitter.com/mathias)!)
diff --git a/src/shared/md/2010-09-16-eval-changes.md b/src/shared/md/2010-09-16-eval-changes.md
index bb2beaf..60b0d6c 100644
--- a/src/shared/md/2010-09-16-eval-changes.md
+++ b/src/shared/md/2010-09-16-eval-changes.md
@@ -1,9 +1,9 @@
eval() is a mysterious function. More so than people believe, hell, its spec isn't even clear. And so i present... The two stages of eval denial.
Try out these functions with
-
+
[foo("foo=2"),foo]
-
+
and take that path with me.
Tested on chrome, firefox, opera, and safari.
@@ -12,16 +12,16 @@ Tested on chrome, firefox, opera, and safari.
#### Apparently eval is evil.
Doesn't seem so evil.
-```
+
function foo(x){var foo=1;eval(x);return foo;};
//[2,function foo(x){var foo=1;eval(x);return foo;}]
-```
+
#### Apparently assigning eval to a variable changes how it acts. WTF.
...Ok I can deal with that I guess.
-```
+
function foo(x){var foo=1, bar=eval;bar(x);return foo;};
//and just returning it, not saving it
@@ -29,4 +29,4 @@ Doesn't seem so evil.
function foo(x){var foo=1;(function(){return eval})(x);return foo;};
//[1, 2]
-```
\ No newline at end of file
+
diff --git a/src/shared/md/2010-10-15-ie-754.md b/src/shared/md/2010-10-15-ie-754.md
index 31b043b..b1ba472 100644
--- a/src/shared/md/2010-10-15-ie-754.md
+++ b/src/shared/md/2010-10-15-ie-754.md
@@ -1,9 +1,9 @@
You wouldn't believe me...
-```
+
ie-754
//=> -754
-```
+
Edit: I think this is a WTF WebKit
diff --git a/src/shared/md/2010-11-10-false-advertising.md b/src/shared/md/2010-11-10-false-advertising.md
index c3469a2..e691e4e 100644
--- a/src/shared/md/2010-11-10-false-advertising.md
+++ b/src/shared/md/2010-11-10-false-advertising.md
@@ -1,40 +1,40 @@
What do you think this constructor returns for `new Dude('Bob')`? Doug or Bob?
-```
+
function Dude(name){
this.name = name;
return {name: 'Doug'};
}
-```
+
Answer:
-```
+
var bob = new Dude('Bob');
// { name: 'Doug' }
bob instanceof Dude
// false
-```
+
Huh!? So you can just slip in anything? What about arrays?
-```
+
function Dude(name){
this.name = name;
return [1, 2, 3];
}
new Dude('Bob');
// [1, 2, 3]
-```
+
That can't be! What about...
-```
+
function Dude(name){
this.name = name;
return 3;
}
new Dude('Bob');
// { name: 'Bob' }
-```
+
Wah? No way! So, if you try to return a primitive type from a constructor(number, string, date), it
will ignore the return value and return the originally initialized object, but otherwise, the returned value overrides.
---- [@airportyh](http://twitter.com/airportyh)
\ No newline at end of file
+--- [@airportyh](http://twitter.com/airportyh)
diff --git a/src/shared/md/2010-11-15-i-am-myself-but-also-not-myself.md b/src/shared/md/2010-11-15-i-am-myself-but-also-not-myself.md
index cca61a7..a24485b 100644
--- a/src/shared/md/2010-11-15-i-am-myself-but-also-not-myself.md
+++ b/src/shared/md/2010-11-15-i-am-myself-but-also-not-myself.md
@@ -1,10 +1,10 @@
Sometimes JavaScript has identity crisis:
-```
+
var foo = [0];
console.log(foo == !foo);
console.log(foo == foo);
-```
+
Is it time to have a "maybe" operator? :-P
diff --git a/src/shared/md/2010-12-06-convert-to-integer.md b/src/shared/md/2010-12-06-convert-to-integer.md
index ccb5419..45c4cbf 100755
--- a/src/shared/md/2010-12-06-convert-to-integer.md
+++ b/src/shared/md/2010-12-06-convert-to-integer.md
@@ -1,6 +1,6 @@
The following will return an Integer with a default of 0 from any String or Number.
-```
+
function toInt(number) {
return number && + number | 0 || 0;
}
@@ -12,7 +12,7 @@ The following will return an Integer with a default of 0 from any String or Numb
console.log(toInt("0")); // 0
console.log(toInt(Number.NaN)); // 0
console.log(toInt(1/0)); // 0
-```
+
Explanation
--
diff --git a/src/shared/md/2011-02-11-all-your-commas-are-belong-to-Array.md b/src/shared/md/2011-02-11-all-your-commas-are-belong-to-Array.md
index dcc0eb9..7f6dc3b 100644
--- a/src/shared/md/2011-02-11-all-your-commas-are-belong-to-Array.md
+++ b/src/shared/md/2011-02-11-all-your-commas-are-belong-to-Array.md
@@ -2,9 +2,9 @@ This installment of wtfjs has to do with the Abstract Equality Comparison Algori
Let's take the following example:
-
+
new Array([],null,undefined,null) == ",,,"; // true
-
+
WTF? Why does this work?
@@ -51,7 +51,7 @@ joining all the internal members of the array with the default separator is the
When an Array calls join on itself, it's going from 1 .. len (all it's members) and calling `ToString` on these members and concatenating
them together. Essentially doing this:
-```
+
Array.prototype.join = function (separator) {
var result = "";
if ("undefined" === typeof separator) {
@@ -63,16 +63,16 @@ them together. Essentially doing this:
}
return result;
};
-```
+
So in the end, we end up with weird stuff like this actually working, as `[]`, `null`, and `undefined` all result in "" when their
respective `ToPrimitive` methods ask for `[[DefaultValue]]` with String as the type hint.
Another similar WTF on the same topic:
-
+
",,," == new Array(4); // true
-
+
This is similar, but not quite the same. When you call Array's constructor, if there are multiple arguments, they're intepretted as being
members of the Array. If you've only put 1 Integer (n) as the argument, an Array object is initiatilized with (n) `undefined` items.
@@ -83,15 +83,15 @@ Again, from the spec 15.4.2.2 new Array (len):
So essentially end up with
-
+
[undefined,undefined,undefined,undefined].join(),
-
+
Which yields something like:
-
+
"" + String(undefined) + "," + String(undefined) + "," + String(undefined) + "," + String(undefined)
-
+
Which ends up being ",,," (which evaluates to `true`, as it matches).
@@ -101,9 +101,9 @@ constructor, it creates and initialises a new Array object.").
So we can finally end up with the weirdest rendition of this WTF as so:
-
+
",,," == Array((null,'cool',false,NaN,4)); // true
-
+
If this doesn't make you WTF, I'm not sure what will.
diff --git a/src/shared/md/2011-05-12-parseInt-is-not-eval.md b/src/shared/md/2011-05-12-parseInt-is-not-eval.md
index 49051bb..ae6c47a 100644
--- a/src/shared/md/2011-05-12-parseInt-is-not-eval.md
+++ b/src/shared/md/2011-05-12-parseInt-is-not-eval.md
@@ -1,39 +1,39 @@
Remember folks, parseInt() is not eval().
-```
+
parseInt("1", 10); // 1
eval("1") // 1
-```
+
Pretty much the same thing....wait.
-```
+
parseInt("1 + 1", 10); // 1
eval("1 + 1") // 2
-```
+
In the first example the first digit is recognized and the rest of the string is thrown away. How intuitive.
eval() at least gets it right.
-```
+
parseInt("1 - 1", 10); // 1
eval("1 - 1") // 0
-```
+
The string example takes the first digit and just throws out the rest of the string.
And again, eval() with the correct solution.
-```
+
parseInt("1" + "1", 10) // 11
eval("1" + "1") // 11
-```
+
This time they both get the wrong answer, because the strings are concatenated before the numbers are evaluated.
-```
+
parseInt("1" - "1", 10); // 0
eval ("1" - "1") // 0
-```
+
Both right answers, because the subtraction symbol forces the strings into numbers before they get used.
diff --git a/src/shared/md/2011-06-23-parseint-magic.md b/src/shared/md/2011-06-23-parseint-magic.md
index b2736d2..70bbdbf 100644
--- a/src/shared/md/2011-06-23-parseint-magic.md
+++ b/src/shared/md/2011-06-23-parseint-magic.md
@@ -1,8 +1,8 @@
Be aware of parseInt!
-
+
parseInt(null, 24) === 23 // true
-
+
[Answer and source!](http://stackoverflow.com/q/6459758/269804)
diff --git a/src/shared/md/2011-06-27-min-less-max.md b/src/shared/md/2011-06-27-min-less-max.md
index ee5dc57..305d1e8 100644
--- a/src/shared/md/2011-06-27-min-less-max.md
+++ b/src/shared/md/2011-06-27-min-less-max.md
@@ -1,22 +1,22 @@
This beauty is courtesy of [TiTi](https://github.com/TiTi) ...lets look at some code.
-```
+
Math.max();
// -Infinity
Math.min();
// Infinity
-```
+
Ok, so, there *is* a good reason for this behaviour. It might even make sense if you happen to occasionally omit args from your min/max calls. ;)
-You see, the min/max implementations need something to compare to and Infinity and -Infinity are the only safe values to use for that comparison. [@kriskowell goes into more better detail here](https://twitter.com/#!/kriskowal/status/85402842650783744) and was quickly followed by [@brendaneich](https://twitter.com/#!/BrendanEich/status/85406752136368128) who not only [wrote js in 10 days](http://brendaneich.com/2008/04/popularity/) but can rock out unicode Infinity symbols without looking them up ...I shit you not.
+You see, the min/max implementations need something to compare to and Infinity and -Infinity are the only safe values to use for that comparison. [@kriskowell goes into more better detail here](https://twitter.com/#!/kriskowal/status/85402842650783744) and was quickly followed by [@brendaneich](https://twitter.com/#!/BrendanEich/status/85406752136368128) who not only [wrote js in 10 days](http://brendaneich.com/2008/04/popularity/) but can rock out unicode Infinity symbols without looking them up ...I shit you not.
Of course, due to this behaviour js allows for this code humour:
-```
+
Math.min() < Math.max();
// false
-```
+
Oh JavaScript, I still love you.
diff --git a/src/shared/md/2011-07-26-iteration-demoralization.md b/src/shared/md/2011-07-26-iteration-demoralization.md
index 4922625..33aafca 100644
--- a/src/shared/md/2011-07-26-iteration-demoralization.md
+++ b/src/shared/md/2011-07-26-iteration-demoralization.md
@@ -1,6 +1,6 @@
See if you can guess what this will output:
-```
+
function allNames() {
var names = [ 'dan', 'anthony', 'pavel' ];
for (name in names) {
@@ -9,7 +9,7 @@ See if you can guess what this will output:
}
allNames();
-```
+
If you guessed this:
@@ -22,9 +22,9 @@ If you guessed this:
What you might not have guessed, is what this will output:
-
+
console.log(window.name);
-
+
it's:
@@ -35,14 +35,14 @@ Iteration is assignment, and without the use of the `var` keyword, you're really
So the original function is equivalent to:
-```
+
function allNames() {
var names = [ 'dan', 'anthony', 'pavel' ];
for (window.name in names) {
console.log(name);
}
}
-```
+
By [@danlash][1]
diff --git a/src/shared/md/2011-09-24-Date-silently-accepts-anything.md b/src/shared/md/2011-09-24-Date-silently-accepts-anything.md
index aa02346..c43ce3d 100644
--- a/src/shared/md/2011-09-24-Date-silently-accepts-anything.md
+++ b/src/shared/md/2011-09-24-Date-silently-accepts-anything.md
@@ -1,10 +1,10 @@
-```
+
d = new Date("couldn't you please throw an exception here instead?");
// No! You get the joy of discovering this error somewhere unrelated,
// much later; at the point of use, in an innocent part of your code:
d.getTime(); // => NaN
-```
+
[johan](https://github.com/johan) || [@ecmanaut](http://twitter.com/ecmanaut)
diff --git a/src/shared/md/2011-11-08-undefined-identity-crisis.md b/src/shared/md/2011-11-08-undefined-identity-crisis.md
index ba413e0..529419d 100644
--- a/src/shared/md/2011-11-08-undefined-identity-crisis.md
+++ b/src/shared/md/2011-11-08-undefined-identity-crisis.md
@@ -1,6 +1,6 @@
Everyone loves Yoda Conditionals, right? They stop you from accidentally assigning stuff when you should be comparing, breaking everything! Or do they?
-```
+
function test (a) {
if (undefined = a) {
a = {}
@@ -8,7 +8,7 @@ Everyone loves Yoda Conditionals, right? They stop you from accidentally assigni
return a;
}
undefined === test(null)
-```
+
I encountered this gem recently. It's more a bug in the code than the implementation, but it's the implementation that allows this quirky disaster to occur. A single missing equals symbol in the comparison of undefined against a is the source of the chaos.
diff --git a/src/shared/md/2011-11-11-the-universe-answers-and-JavaScript-still-makes-us-wtf.md b/src/shared/md/2011-11-11-the-universe-answers-and-JavaScript-still-makes-us-wtf.md
index cfac9a1..c812772 100644
--- a/src/shared/md/2011-11-11-the-universe-answers-and-JavaScript-still-makes-us-wtf.md
+++ b/src/shared/md/2011-11-11-the-universe-answers-and-JavaScript-still-makes-us-wtf.md
@@ -4,10 +4,10 @@ arithmetics and operator ambiguity / overloading.
If you can figure out what this returns on the first guess, I'll give you a
great big hug the next time I see you:
-```
+
// is there an error (if not, what do I return?)
"3" -+-+-+ "1" + "1" / "3" * "6" + "2"
-```
+
Now, I won't spoil the fun for those of you at home trying to do this mentally,
but the answer probably isn't what you'd expect. Go ahead, run it in a
@@ -20,7 +20,7 @@ than that, aren't we?).
The precedence of operators in JavaScript are (from highest to lowest):
-```
+
delete
void
typeof
@@ -74,7 +74,7 @@ The precedence of operators in JavaScript are (from highest to lowest):
&=
^=
|=
-```
+
http://es5.github.com/#x11.4.6
@@ -123,7 +123,7 @@ NOTE: This ignores your grammar teacher's rules about double negatives.
Let's make this line into an expression tree. After unary operators are
evaluated, we have:
-```
+
+
"2" +
@@ -133,12 +133,12 @@ evaluated, we have:
/ "6" 1 "3"
"1" "3"
-```
+
However, we don't know what types are implicitly cast yet. Let's make another
tree showing non-ambiguous operations (`/`, `*`, `-`):
-```
+
+
"2" +
@@ -148,26 +148,26 @@ tree showing non-ambiguous operations (`/`, `*`, `-`):
/ 6 1 3
1 3
-```
+
This greatly simplifies the bottom of the tree as they're all now numbers. We
continue evaluating from bottom left most child up, which evaluates the
expression as so: (3-1)+((1/3)*2) = 2 + 2 = 4. This leaves us with this tree:
-```
+
+
"2" 4
-```
+
This last operation is ambiguous, so we look to see if either operand is a
string (which `"2"` is), so the type of `lprim` or `rprim` is `String` after
calling `ToPrimitive` (which `rprim is`), so the final result is
-```
+
"42"
-```
+
(which is the obvious answer to life the universe and everything, really).
diff --git a/src/shared/md/2011-12-16-negative-zero-equal-but-not-equal.md b/src/shared/md/2011-12-16-negative-zero-equal-but-not-equal.md
index d5f901a..ef0f232 100644
--- a/src/shared/md/2011-12-16-negative-zero-equal-but-not-equal.md
+++ b/src/shared/md/2011-12-16-negative-zero-equal-but-not-equal.md
@@ -1,7 +1,7 @@
-```
+
0 === -0 //true
1/0 === 1/-0 //false
-```
+
By [Benvie][1]
diff --git a/src/shared/md/2012-04-18-changing-variables-changes-arguments.md b/src/shared/md/2012-04-18-changing-variables-changes-arguments.md
index 8cec419..50333bd 100644
--- a/src/shared/md/2012-04-18-changing-variables-changes-arguments.md
+++ b/src/shared/md/2012-04-18-changing-variables-changes-arguments.md
@@ -1,14 +1,14 @@
It turns out that changing the value of an argument variable will change its
value in the `arguments` "array":
-```
+
> function hello(what) {
. what = "world";
. return "Hello, " + arguments[0] + "!";
. }
> hello("shazow")
"Hello, world!"
-```
+
This is documented behaviour (see *NOTE 1* in §10.6 *Arguments Object* of
[ECMA-262](http://es5.github.com/#x10.6)).
diff --git a/src/shared/md/2012-05-07-Numbers-and-dots.md b/src/shared/md/2012-05-07-Numbers-and-dots.md
index 0b3d08d..01da73d 100644
--- a/src/shared/md/2012-05-07-Numbers-and-dots.md
+++ b/src/shared/md/2012-05-07-Numbers-and-dots.md
@@ -1,6 +1,6 @@
A JavaScript syntax oddity with Numbers and Dots:
-```
+
// Ok, you may have seen wrapping a number literal with parens to call Number methods
(42).toFixed(2); // "42.00"
@@ -15,7 +15,7 @@ A JavaScript syntax oddity with Numbers and Dots:
// Hey, so what about 3 dots!? Firefox gives XML-related error (WTF?)
42...toFixed(2); // TypeError: XML descendants internal method called on incompatible Number
-```
+
[kensnyder](https://github.com/kensnyder) via [@ryanflorence](https://twitter.com/ryanflorence/status/199523604092821504)
diff --git a/src/shared/md/2012-08-11-Slashes!.md b/src/shared/md/2012-08-11-Slashes!.md
index d582ecd..4b9cfd2 100644
--- a/src/shared/md/2012-08-11-Slashes!.md
+++ b/src/shared/md/2012-08-11-Slashes!.md
@@ -1,18 +1,18 @@
What should the following JS yield?
-```
+
n = 1
/1*"\/\//.test(n + '"//')
-```
+
Should it be `true`? (It is `NaN`.)
Using semicolons, on the other hand, makes it behave like you'd expect:
-```
+
n = 1;
/1*"\/\//.test(n + '"//');
-```
+
(Returns `true`.)
@@ -35,10 +35,10 @@ concatenation.
An interesting variation that shows what happens more clearly is the following:
-```
+
n = 1
/1?":n\/\//.test(n + '":n//')
-```
+
That returns `":n///.test(n + '"`. It gives the trick away.
(It uses the ternary operator `?:`, if you're wondering.)
@@ -46,10 +46,10 @@ That returns `":n///.test(n + '"`. It gives the trick away.
Obviously, if you really want your friends to have a headache, give them this
version:
-```
+
n = 0
/0?":n\/\//.test(n + '":n//')
-```
+
That returns `undefined`, which is even more obscure than the `NaN` that we got
in the first snippet.
diff --git a/src/shared/md/2012-09-19-Hexadecimal-weirdness.md b/src/shared/md/2012-09-19-Hexadecimal-weirdness.md
index 3207b4a..cf421ac 100644
--- a/src/shared/md/2012-09-19-Hexadecimal-weirdness.md
+++ b/src/shared/md/2012-09-19-Hexadecimal-weirdness.md
@@ -1,20 +1,20 @@
In JS you can represent numbers in hexadecimal, right?
-
+
var hex = 0xFF55;
-
+
You can also perform shift operations, right?
Left shift is equivalent to a multiplication...
-```
+
var hex = 0xFF55 << 8; // Shift 8 bits = add 0x00 at the end.
alert(hex.toString(16)); // 0xFF5500
-```
+
But from a certain point, this produces negative numbers
-```
+
// Before 0x800000 it's ok
alert((0x777777 << 8).toString(16)); // 0x77777700
@@ -23,7 +23,7 @@ But from a certain point, this produces negative numbers
// The only way to remain positive is to multiply instead of shifting
alert((0x888888 * 0x100).toString(16)); // 88888800
-```
+
Thanks JS for making left shift different than a multiplication!
@@ -44,9 +44,9 @@ So in binary:
As for why multiplying 0x888888 * 0x100 yields a different result, both operands to the * operator are numeric, so
each is casted to a IEEE 64-bit double, then multiplied, which means this is what is really happening:
-```
+
0x888888 * 0x100 === 8947848.0 * 256.0 === 2290649088.0
-```
+
When this is converted into a string with base 16, what you get is 88888800.
diff --git a/src/shared/md/2012-10-10-infinity-madness.md b/src/shared/md/2012-10-10-infinity-madness.md
index 8d00f80..8286dd3 100644
--- a/src/shared/md/2012-10-10-infinity-madness.md
+++ b/src/shared/md/2012-10-10-infinity-madness.md
@@ -1,13 +1,13 @@
-```js
+
parseFloat( 'Infinity' ) // returns Infinity
Number( 'Infinity' ) // returns Infinity
parseInt( 'Infinity' ) // returns NaN
-```
+
— [@fivetanley][1]
But of course, you should always specify a radix when calling `parseInt`:
-```js
+
parseInt( 'Infinity', 10 ) // returns NaN
// ...
parseInt( 'Infinity', 18 ) // returns NaN...
@@ -24,7 +24,7 @@ But of course, you should always specify a radix when calling `parseInt`:
parseInt( 'Infinity', 36 ) // returns 1461559270678...
parseInt( 'Infinity', 37 ) // returns NaN
// ...
-```
+
— [@stuartpb][2]
[1]: https://twitter.com/fivetanley
diff --git a/src/shared/md/2012-12-28-undefined-props-on-numbers.md b/src/shared/md/2012-12-28-undefined-props-on-numbers.md
index 80d1517..427fe99 100644
--- a/src/shared/md/2012-12-28-undefined-props-on-numbers.md
+++ b/src/shared/md/2012-12-28-undefined-props-on-numbers.md
@@ -1,9 +1,9 @@
-```
+
function getBounds(node) {
var n = node || 0;
return { width: n.width, height: n.height };
}
-```
+
If you call `getBounds()` with _null_, you'll get back `{ width: undefined, height: undefined }`
because in JS, numbers have properties (inherited from Number), and using an undefined
diff --git a/src/shared/md/2013-01-28-array-comparison.md b/src/shared/md/2013-01-28-array-comparison.md
index 1f755e6..80ce94e 100644
--- a/src/shared/md/2013-01-28-array-comparison.md
+++ b/src/shared/md/2013-01-28-array-comparison.md
@@ -1,25 +1,25 @@
Did you know that JavaScript can compare arrays using lexicographical ordering?
-```
+
[1, 2, 4] < [1, 2, 5] // true
[1, 3, 4] < [1, 2, 5] // false
-```
+
Just don't expect trichotomy to hold.
-```
+
[1, 2, 3] === [1, 2, 3] // false
[1, 2, 3] < [1, 2, 3] // false
[1, 2, 3] == [1, 2, 3] // false
[1, 2, 3] > [1, 2, 3] // false
-```
+
Oh, and just in case you're wondering, it knows it's messing with you.
-```
+
[1, 2, 3] <= [1, 2, 3] // true
[1, 2, 3] >= [1, 2, 3] // true
-```
+
— [@pwnall][1]
@@ -37,7 +37,7 @@ return the result of the comparison ToPrimitive(x) == y.
10.Return false.
-```
+
[] === []; // false
[] == []; // false
@@ -47,7 +47,7 @@ return the result of the comparison ToPrimitive(x) == y.
//BUT
[] == 0; // true
-```
+
http://www.ecma-international.org/ecma-262/5.1/#sec-11.8.1
@@ -55,22 +55,22 @@ The Less-than Operator ( < ) and The Greater-than Operator ( > )
5.Let r be the result of performing abstract relational comparison lval < rval or lval > rval.
6.If r is undefined, return false. Otherwise, return r.
-```
+
[] < []; // false
[] > []; // false
// its like 1 < 1 ==> false and 1 > 1 ==> false
-```
+
http://www.ecma-international.org/ecma-262/5.1/#sec-11.8.3
5.Let r be the result of performing abstract relational comparison rval < lval with LeftFirst equal to false.
6.If r is true or undefined, return false. Otherwise, return true.
-```
+
[] <= []; // true
[] >= []; // true
// its like 1 <= 1 ==> true and 1 >= 1 ==> true
-```
+
— [kirillov-artur][1]
diff --git a/src/shared/md/2013-02-05-magic-function-properties.md b/src/shared/md/2013-02-05-magic-function-properties.md
index ee71852..8e80457 100644
--- a/src/shared/md/2013-02-05-magic-function-properties.md
+++ b/src/shared/md/2013-02-05-magic-function-properties.md
@@ -1,22 +1,22 @@
-```
+
var f = function() { };
f.foo = 'foo'; // sets f.foo to 'foo'
-```
+
Functions are objects, so you can set properties on them after creation.
-```
+
f.name; // is ''
f.name = 'foo';
f.name; // is still ''
-```
+
But not all the time.
-```
+
var f = function myFunction() { };
f.name; // is 'myFunction'
-```
+
Functions happen to have magic properties. One of them is the non-standard `.name`,
which stores the function's first name and read-only.
diff --git a/src/shared/md/2013-02-12-obfuscated-fibonacci.md b/src/shared/md/2013-02-12-obfuscated-fibonacci.md
index e1985aa..491944a 100644
--- a/src/shared/md/2013-02-12-obfuscated-fibonacci.md
+++ b/src/shared/md/2013-02-12-obfuscated-fibonacci.md
@@ -1,4 +1,4 @@
-```
+
var fib = function (_) {
for(_=[+[],++[[]][+[]],+[],_],_[++[++[++[[]][+[]]][+[]]][+[]]]=(((_[++[++[++[[]][+[]]][+[]]][+[]]]-(++[[]][+[]]))&(((--[[]][+[]])>>>(++[[]][+[]]))))===(_[++[++[++[[]][+[]]][+[]]][+[]]]-(++[[]][+[]])))?(_[++[++[[]][+[]]][+[]]]=++[[]][+[]],_[++[++[++[[]][+[]]][+[]]][+[]]]-(++[[]][+[]])):+[];_[++[++[++[[]][+[]]][+[]]][+[]]]--;_[+[]]=(_[++[[]][+[]]]=_[++[++[[]][+[]]][+[]]]=_[+[]]+_[++[[]][+[]]])-_[+[]]);
return _[++[++[[]][+[]]][+[]]];
@@ -19,7 +19,7 @@
console.assert(fib(63) === 6557470319842);
console.log('done!');
-```
+
I've combined (for fun) a few WTFs to make something bigger.
diff --git a/src/shared/md/2013-02-13-unicode-vars.md b/src/shared/md/2013-02-13-unicode-vars.md
index 9c2e728..ccc7b93 100644
--- a/src/shared/md/2013-02-13-unicode-vars.md
+++ b/src/shared/md/2013-02-13-unicode-vars.md
@@ -1,6 +1,6 @@
ECMAScript allows you to use unicode variable names, just use the usual \uXXXX codes:
-```
+
var \u1000 = {
\u1001: 'foo',
\u1011: 'bar'
@@ -8,7 +8,7 @@ ECMAScript allows you to use unicode variable names, just use the usual \uXXXX c
console.log( \u1000.\u1001 ); // prints 'foo'
console.log( \u1000.\u1011 ); // prints 'bar'
-```
+
WTF right?
diff --git a/src/shared/md/2013-02-21-why-am-i-a-number.md b/src/shared/md/2013-02-21-why-am-i-a-number.md
index 56d4974..cbf30b8 100644
--- a/src/shared/md/2013-02-21-why-am-i-a-number.md
+++ b/src/shared/md/2013-02-21-why-am-i-a-number.md
@@ -1,8 +1,8 @@
Can someone tell me?
-```
+
"Why am I a " + typeof + ""; // "Why am I a number"
-```
+
— [@jhnnns][1]
@@ -15,13 +15,13 @@ can be used as an unary operator (syntax is: + UnaryExpression). + converts its
Note that we can cast strings to numbers by preceding them with +:
-```
+
(2 + "3"); // 23
(2 + +"3"); // 5
(+""); // 0
-```
+
— [@wojciechfornal][2]
@@ -29,7 +29,7 @@ Note that we can cast strings to numbers by preceding them with +:
***
-```
+
typeof +""; // number
// even
@@ -42,7 +42,7 @@ typeof -"foo"; // "number"
// because
typeof NaN === 'number'; // Despite being "Not-A-Number"
-```
+
— [kirillov-artur][3]
diff --git a/src/shared/md/2013-02-22-parseint-radix.md b/src/shared/md/2013-02-22-parseint-radix.md
index e196d78..4cd374c 100644
--- a/src/shared/md/2013-02-22-parseint-radix.md
+++ b/src/shared/md/2013-02-22-parseint-radix.md
@@ -1,7 +1,7 @@
-```
+
parseInt('fuck'); // NaN
parseInt('fuck', 16); // 15
-```
+
So remember kids, always supply a radix!
@@ -11,10 +11,10 @@ So remember kids, always supply a radix!
This occurs because parseInt will continue parsing character-by-character
until it hits a character it doesn't know. The `f` in `fuck` is hexadecimal
15. You can get similar behavior with:
-```
+
parseInt('3fucks') // 3
parseInt('3fucks', 16) // 3f in hex = 63
-```
+
[1]:https://twitter.com/kevincennis
[2]:https://github.com/stevendesu
diff --git a/src/shared/md/2013-02-28-null,-undefined-and-test.md b/src/shared/md/2013-02-28-null,-undefined-and-test.md
index 1296d76..77b26ef 100644
--- a/src/shared/md/2013-02-28-null,-undefined-and-test.md
+++ b/src/shared/md/2013-02-28-null,-undefined-and-test.md
@@ -2,10 +2,10 @@ Checking a variable for one word with one to ten letters lowercase only?
Try this regular expression: `/^[a-z]{1,10}$/.test('wakaluba')`.
-```
+
/^[a-z]{1,10}$/.test(null);
/^[a-z]{1,10}$/.test(undefined);
-```
+
Both should obviously fail, but return **true**. srsly, WTF JS?
@@ -13,9 +13,9 @@ Both should obviously fail, but return **true**. srsly, WTF JS?
This happens because regex.test() converts its parameter to a string:
-```
+
String(null) // "null"
-```
+
The string "null" matches the regular expression `/^[a-z]{1,10}$/`
diff --git a/src/shared/md/2013-03-06-false-isnt-false.md b/src/shared/md/2013-03-06-false-isnt-false.md
index 5581fb7..5f611db 100644
--- a/src/shared/md/2013-03-06-false-isnt-false.md
+++ b/src/shared/md/2013-03-06-false-isnt-false.md
@@ -1,7 +1,7 @@
-```
+
true == 'true' // true
false == 'false'; // false
-```
+
This is expected behaviour as == doesn't do value equality,
but rather it does numeric value [equality][1], thus 'false' is truthy, thus equals 1
diff --git a/src/shared/md/2013-03-25-null-to-bool.md b/src/shared/md/2013-03-25-null-to-bool.md
index b451494..2f229d5 100644
--- a/src/shared/md/2013-03-25-null-to-bool.md
+++ b/src/shared/md/2013-03-25-null-to-bool.md
@@ -1,12 +1,12 @@
-```
+
null == false // false
-```
+
Okay, we know this. Null doesn't convert to boolean.
Now try this...
-```
+
!null // true
-```
+
Well, this is awkward.
@@ -14,11 +14,11 @@ Well, this is awkward.
The issue here is that Null **can** be converted to a boolean, it just
isn't **implicitly** converted:
-```
+
Boolean(null) // false
-```
+
-See [The Abstract Equality Comparison Algorithm](http://es5.github.io/#x11.9.3)
+See [The Abstract Equality Comparison Algorithm](http://es5.github.io/#x11.9.3)
Null is only implicitly converted if compared to `undefined`
— [@stevendesu][2]
diff --git a/src/shared/md/2013-03-27-automatic-semicolon-insertion.md b/src/shared/md/2013-03-27-automatic-semicolon-insertion.md
index 7699c6a..66fc257 100644
--- a/src/shared/md/2013-03-27-automatic-semicolon-insertion.md
+++ b/src/shared/md/2013-03-27-automatic-semicolon-insertion.md
@@ -1,6 +1,6 @@
This is another case of an accidental global:
-```
+
var a = 1
b = 1;
@@ -11,7 +11,7 @@ This is another case of an accidental global:
console.log(a); // prints 1
console.log(b); // prints 2
-```
+
While debugging, one might be looking only at the “b” statements, but the
problem is the missing comma after “a”. Since JavaScript has “automatic
diff --git a/src/shared/md/2013-04-18-true-story-bro.md b/src/shared/md/2013-04-18-true-story-bro.md
index a30f39a..bf0544c 100644
--- a/src/shared/md/2013-04-18-true-story-bro.md
+++ b/src/shared/md/2013-04-18-true-story-bro.md
@@ -1,8 +1,8 @@
True story bro!
-
+
'true' == true // returns false
-
+
— [ProfessorWeb][1]
diff --git a/src/shared/md/2013-04-28-isfinite-null-is-true.md b/src/shared/md/2013-04-28-isfinite-null-is-true.md
index 42c6036..5563cc4 100644
--- a/src/shared/md/2013-04-28-isfinite-null-is-true.md
+++ b/src/shared/md/2013-04-28-isfinite-null-is-true.md
@@ -1,25 +1,25 @@
`isFinite` function of JavaScript tests whether a number is finite.
-```
+
isFinite(42); // true
isFinite(1/0); // false
isFinite(0/0); // NaN is not finite -> false
isFinite('42'); // true
isFinite('hi'); // false
-```
+
These are normal results.
-```
+
isFinite(); // false
isFinite(undefined); // false
-```
+
Undefined values are not finite. These are normal results too.
-```
+
isFinite(null); // true
-```
+
Wait, what? Is null a number? [It is converted into 0](http://ecma-international.org/ecma-262/5.1/#sec-9.3)? Why?
diff --git a/src/shared/md/2013-06-20-negative-indexes.md b/src/shared/md/2013-06-20-negative-indexes.md
index 5ff9a9f..a44b2b8 100644
--- a/src/shared/md/2013-06-20-negative-indexes.md
+++ b/src/shared/md/2013-06-20-negative-indexes.md
@@ -1,10 +1,10 @@
Negative numbers mean different things to different functions on the Array prototype.
-```
+
var nums = [1, 2, 3];
nums.splice(nums.indexOf('wtf'), 1);
nums; // [1, 2]
-```
+
— [@markdalgleish][0]
@@ -13,21 +13,21 @@ Interestingly, negative numbers put inside Array.Splice splice the item that is
e.g.
-```
+
var nums = [1, 2, 3, 4, 5];
nums.splice(-1, 1); // removes the last item
nums.splice(-2, 1); // removes the second last item
-```
+
until.......
you reach the start of your array - afterwards, the first item will always be the item spliced:
-```
+
var nums = [1, 2, 3];
nums.splice(-12, 1);
nums; // [2, 3]
-```
+
— [@MichalPaszkiewicz][1]
diff --git a/src/shared/md/2013-07-04-array-constructor.md b/src/shared/md/2013-07-04-array-constructor.md
index 6997bc7..d508609 100644
--- a/src/shared/md/2013-07-04-array-constructor.md
+++ b/src/shared/md/2013-07-04-array-constructor.md
@@ -1,6 +1,6 @@
-```
+
Array(20).map(function(elem) { return 'a'; }); // Array of undefined x 20
-```
+
More info [here](http://www.ecma-international.org/ecma-262/5.1/#sec-15.4.4.19).
Thanks [Paul Irish](https://twitter.com/paul_irish) for the explanation.
diff --git a/src/shared/md/2013-07-18-array-ruse.md b/src/shared/md/2013-07-18-array-ruse.md
index 302040a..09be476 100644
--- a/src/shared/md/2013-07-18-array-ruse.md
+++ b/src/shared/md/2013-07-18-array-ruse.md
@@ -1,6 +1,6 @@
-``` javascript
+ javascript
[,,,].join() // ==> ",,"
-```
+
wtf?
@@ -21,9 +21,9 @@ allowed by Javascript and that's the case. So `[1,2,3,]` equals to `[1,2,3]`.
So literally `[,,,]` is something like `[undefined, undefined, undefined,]`.
You can add `undefined` to the end explicitly to get an array with 4 elements:
-``` javascript
+ javascript
[,,,undefined].join() // ==> ',,,'
-```
+
— [@ixti][3]
diff --git a/src/shared/md/2013-08-07-Math.max()-behaviour.md b/src/shared/md/2013-08-07-Math.max()-behaviour.md
index cd0838c..bfc5dd1 100644
--- a/src/shared/md/2013-08-07-Math.max()-behaviour.md
+++ b/src/shared/md/2013-08-07-Math.max()-behaviour.md
@@ -1,7 +1,7 @@
`Math.max()` has an interesting behaviour, handling different **JavaScript data
types** in different ways.
-```
+
Math.max(3, 0); // 3
Math.max(3, {}); // NaN
Math.max(3, []); // 3
@@ -9,25 +9,25 @@ types** in different ways.
Math.max(3, 'foo'); // NaN
Math.max(-1, null); // 0
Math.max(-1, undefined); // NaN
-```
+
Now, let's focus on **Booleans**:
-```
+
Math.max(1, true); // 1
Math.max(0, true); // 1
Math.max(1, false); // 1
Math.max(-1, true); // 1
Math.max(-1, false); // 0
-```
+
And now, on **Arrays**:
-```
+
Math.max(-1, []); // 0
Math.max(-1, [1]); // 1
Math.max(-1, [1, 4]); // NaN
-```
+
So next time, watch out for what you pass into `Math.max()`.
@@ -36,9 +36,9 @@ So next time, watch out for what you pass into `Math.max()`.
`Math.max()` typecasts all values to Numbers (`Number(x)`), e.g.:
-``` javascript
+ javascript
Math.max(false, -1); // 0
Math.max(5, "10"); // 10
-```
+
— [@ixti](http://ixti.net)
diff --git a/src/shared/md/2013-09-30-Array-Constructor2-is-Very-Undefined.md b/src/shared/md/2013-09-30-Array-Constructor2-is-Very-Undefined.md
index c630a94..50016d6 100644
--- a/src/shared/md/2013-09-30-Array-Constructor2-is-Very-Undefined.md
+++ b/src/shared/md/2013-09-30-Array-Constructor2-is-Very-Undefined.md
@@ -2,13 +2,13 @@ Have you ever thought that `Array(3)` will return you an array of 3 `undefined`'
the same as `[undefined,undefined,undefined]`?
So try this:
-```
+
Array(3).forEach(function(elem) { console.log(elem); });
-```
+
And you will get no result at all, however
-```
+
[undefined,undefined,undefined].forEach(function(elem) { console.log(elem); });
-```
+
will give you 3 nice log entries.
Are the first example's `undefined` less defined than the second example's `undefined`s?
diff --git a/src/shared/md/2013-10-02-implicit-getElementById.md b/src/shared/md/2013-10-02-implicit-getElementById.md
index 3da3dc6..4c96094 100644
--- a/src/shared/md/2013-10-02-implicit-getElementById.md
+++ b/src/shared/md/2013-10-02-implicit-getElementById.md
@@ -1,18 +1,18 @@
document.getElementById can be omitted in all major browsers, including IE6+.
This is non-standard, but all of them save the elements ids as globals.
-```
+
-```
+
Or do they? Let's search myId in the window object.
-```
+
// Way 1
alert('myId' in window); // --> true (right...)
// Way 2
@@ -23,13 +23,13 @@ Or do they? Let's search myId in the window object.
}
}
alert(present); // --> false (wat!)
-```
+
Looks like all browsers create Shroedinger's globals, that are here and not here at the same time...
What happens to globals when an element with the same id is created?
-```
+
@@ -40,14 +40,14 @@ What happens to globals when an element with the same id is created?
global0.innerHTML = "global0"; // --> nothing happens
alert(global0); // --> 1
-```
+
So implicit getElementById's can't overload global vars, be they native or custom.
What about the other way? Well, it depends on how the global var is set.
Let's try with "window."
-```
+
-```
+
OK.
Let's try without any prefix.
-```
+
-```
+
Weird.
And what happens if the global var is declared with "var" ?
-```
+
-```
+
WAT.
diff --git a/src/shared/md/2013-10-07-Local-storage-limitations.md b/src/shared/md/2013-10-07-Local-storage-limitations.md
index 231e5f9..c50e786 100644
--- a/src/shared/md/2013-10-07-Local-storage-limitations.md
+++ b/src/shared/md/2013-10-07-Local-storage-limitations.md
@@ -1,13 +1,13 @@
The **local storage** functionality in browsers is a bit limited and this can
lead to some rather surprising behaviour.
-```
+
localStorage[0] = false;
if (localStorage[0]) {
console.log('wtf'); // runs?!
}
-```
+
When checking the value stored in `localStorage`, it appears that the boolean
was silently converted to the string `"false"`, which is truthy.
diff --git a/src/shared/md/2013-12-15-charAt-is-not-the-same-as-[].md b/src/shared/md/2013-12-15-charAt-is-not-the-same-as-[].md
index 337fd82..34556b9 100644
--- a/src/shared/md/2013-12-15-charAt-is-not-the-same-as-[].md
+++ b/src/shared/md/2013-12-15-charAt-is-not-the-same-as-[].md
@@ -1,12 +1,12 @@
In case someone tells you it doesn't matter how you access characters in strings, they're wrong:
-
+
'hello'[1] // 'e'
'hello'.charAt(1) // 'e'
'hello'[-1] // undefined
'hello'.charAt(-1) // ''
-
+
What better "character" than the empty string to say "no such index"?
diff --git a/src/shared/md/2013-12-19-The-Hungry-Variable.md b/src/shared/md/2013-12-19-The-Hungry-Variable.md
index 6d77f44..fb08dad 100644
--- a/src/shared/md/2013-12-19-The-Hungry-Variable.md
+++ b/src/shared/md/2013-12-19-The-Hungry-Variable.md
@@ -1,21 +1,21 @@
Consider this JS:
-```
+
x = /[/ + "javascript"[0] + '///'
-```
+
What do you expect the value of `x` to be?
Those well-versed in Javascript's concatenation may either reject the statement
or perhaps say:
-```
+
"/[/j///"
-```
+
Chromium's console, however says:
-```
+
x = /[/ + "javascript"[0] + '///'
/[/ + "javascript"[0] + '/
-```
+
### The Hungry Variable
Those who don't immediately see through this may notice a few things.
@@ -27,13 +27,13 @@ Those who don't immediately see through this may notice a few things.
What should be noted is that the errors for `/(/` and `/[/` are subtly
different. In Chromium console:
-```
+
/(/
//SyntaxError: Invalid regular expression: /(/: Unterminated group
/[/
//SyntaxError: Invalid regular expression: missing /
-```
+
It seems that Javascript cannot see the second `/` for some reason. This is
because choice groups (`/[any letter]/`) don't require escaping of the forward-
@@ -53,14 +53,14 @@ the `//'` is simply a comment.
If you want the pre to do as expected, add a single forward slash before the
first "[":
-```
+
x = /\[/ + "javascript"[0] + '///'
"/\[/j///"
//for comparison
x = /[/ + "javascript"[0] + '///'
/[/ + "javascript"[0] + '/
-```
+
It is an interesting example of a statement that can completely change meaning
with the insertion of one character without creating any errors.
diff --git a/src/shared/md/2014-01-29-regular-expression-and-slash.md b/src/shared/md/2014-01-29-regular-expression-and-slash.md
index 42929d5..104724c 100644
--- a/src/shared/md/2014-01-29-regular-expression-and-slash.md
+++ b/src/shared/md/2014-01-29-regular-expression-and-slash.md
@@ -2,7 +2,7 @@ When I use regular expressions and I want to validate a range of letters, I can
do it using `a-z` or `A-Z`. Even when I use `A-z` it works fine too. The problem
comes doing some test:
-```
+
/[A-Z]/.test("A"); // true
/[A-Z]/.test("b"); // false
/[A-Z]/.test("Z"); // true
@@ -11,11 +11,11 @@ comes doing some test:
/[a-z]/.test("A"); // false
/[a-z]/.test("z"); // true
/[a-z]/.test("Z"); // false
-```
+
The weird thing comes when I do this test:
-```
+
/[A-z]/.test("A"); // true
/[A-z]/.test("a"); // true
/[A-z]/.test("Z"); // true
@@ -23,7 +23,7 @@ The weird thing comes when I do this test:
/[A-z]/.test("m"); // true
/[A-z]/.test("D"); // true
/[A-z]/.test("\\"); // true WTF?
-```
+
It's supposed to accept only letters from `A to Z` and `a to z`.
Can someone explain this?
@@ -32,47 +32,47 @@ Can someone explain this?
I had a look into this with the following code:
-```javascript
+
var re = /[A-z]/g,s=(function(){
var f = String.fromCharCode;
for(var i=0;i<6000;i++) f=f.bind(0, i);
return f();
})(),q,z=[];while((q=re.exec(s)) != null) z.push(q[0]);z
-```
+
It returns
-```javascript
+
["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O",
"P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "[", "\", "]", "^",
"_", "`", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
-```
+
A-z literally means 'any character between 'A' and
'z' in unicode code-point order, or at least charCode order. This allows (I
think non-standard) statements like `/[ -y]/g`:
-```javascript
+
var re = /[ -y]/g,s=(function(){
var f = String.fromCharCode;
for(var i=0;i<6000;i++) f=f.bind(0, i);
return f();
})(),q,z=[];while((q=re.exec(s)) != null) z.push(q[0]);z
-```
+
Which returns
-```javascript
+
[" ", "!", """, "#", "$", "%", "&", "'", "(", ")", "*", "+", ",", "-", ".",
"/", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ":", ";", "<", "=",
">", "?", "@", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L",
"M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "[",
"\", "]", "^", "_", "`", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j",
"k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y"]`
-```
+
This probably has some potential security implications because if you're using
-[A-z] to sanitise something, you'll accept [\]^_`
+[A-z] to sanitise something, you'll accept [\]^_`
A very interesting find!
diff --git a/src/shared/md/2014-02-04-Date.Date-vs-Year.md b/src/shared/md/2014-02-04-Date.Date-vs-Year.md
index 167b7f1..23415c5 100644
--- a/src/shared/md/2014-02-04-Date.Date-vs-Year.md
+++ b/src/shared/md/2014-02-04-Date.Date-vs-Year.md
@@ -1,11 +1,11 @@
`Date.getDate()` returns the day of the Month, whereas `Date.getMonth()` returns the previous month (somehow *zero-indexed*).
-```
+
var date = new Date('Tue Apr 01 2014')
date // Tue Apr 01 2014 00:00:00 GMT+0200
date.getDate() // 1
date.getMonth() // 3
-```
+
— [@depoulo](https://github.com/depoulo)
diff --git a/src/shared/md/2014-02-20-math-pow.md b/src/shared/md/2014-02-20-math-pow.md
index 7421890..ae708cc 100644
--- a/src/shared/md/2014-02-20-math-pow.md
+++ b/src/shared/md/2014-02-20-math-pow.md
@@ -1,35 +1,35 @@
[The spec of ECMAScript](http://ecma-international.org/ecma-262/5.1/#sec-15.8.2.13) specifies some default values of `Math.pow`.
-```
+
console.log(Math.pow(NaN, 42) === NaN)
-```
+
[Oops, sorry.](https://wtfjs.com/wtfs/2010-02-12-not-a-number-is-not-a-not-a-number)
-```
+
console.log(Math.pow(NaN, 42)); // NaN
-```
+
As you can see, if the first argument is `NaN`, `Math.pow` returns `NaN`, which is quite normal.
However, there's an exception: when the second argument is `0` (`+0` or `-0`).
-```
+
console.log(Math.pow(NaN, 0)); // 1
-```
+
When the second argument is `0`, then `Math.pow` should return `1`, no matter what the first argument is.
This can be considered as a normal behavior, unless...
-```
+
console.log(Math.pow(Infinity, 0), Math.pow(0, 0)); // Still 1?
-```
+
Basically the spec asserts values of some [indeterminate forms](http://en.wikipedia.org/wiki/Indeterminate_forms).
Sure, some can argue that lim(x->infinity) x^0 is zero (infinity is not a real number, anyway) and 0^0 is [usually considered as one](http://en.wikipedia.org/wiki/Exponentiation#Zero_to_the_power_of_zero), but according to the same spec...
-```
+
console.log(Math.pow(1, Infinity)); // NaN
-```
+
So 1^infinity is `NaN` while infinity^0 is `1`. Great.
diff --git a/src/shared/md/2014-02-22-wtf_document.all.md b/src/shared/md/2014-02-22-wtf_document.all.md
index 69bb2df..e07603a 100644
--- a/src/shared/md/2014-02-22-wtf_document.all.md
+++ b/src/shared/md/2014-02-22-wtf_document.all.md
@@ -1,9 +1,9 @@
In Chrome
-```
+
document.all // HTMLAllCollection[843]
document.all[0] // ...
typeof document.all // "undefined"! WTF!
!{} // false. It's OK
!document.all // true! WTF!
-```
\ No newline at end of file
+
diff --git a/src/shared/md/2014-02-25-array-indexof.md b/src/shared/md/2014-02-25-array-indexof.md
index 79a4772..9d7cad0 100644
--- a/src/shared/md/2014-02-25-array-indexof.md
+++ b/src/shared/md/2014-02-25-array-indexof.md
@@ -1,38 +1,38 @@
**Not empty array doesn't contain its element:**
-```
+
var a = [,];
a.length; //1, some element exists
a.indexOf(a[0]); //-1
// We have the array with non-zero length, which doesn't contain its first element. WTF?
-```
+
**The problem is in this:**
-`a[0]` is `undefined`. `undefined` is the javascript primitive type. But when we init an array
+`a[0]` is `undefined`. `undefined` is the javascript primitive type. But when we init an array
the ES5 spec tells us the following about [array initialisers](http://es5.github.io/#x11.1.4):
-```
+
Elided array elements are not defined.
...
The missing array element contributes to the length of the Array and increases the index of subsequent elements.
-```
+
Elements are not `undefined`, they are `not initialized`.
When we invoke `indexOf` on an array this is one of the steps that happens:
-```
+
Let kPresent be the result of calling the [[HasProperty]] internal method of O with argument ToString(k).
-```
+
-In that, `k` is a number corresponding to an array index and `O` is the array itself.
+In that, `k` is a number corresponding to an array index and `O` is the array itself.
Since elided elements were not defined the array does not have a property for the corresponding index.
*Ok. But why do we get `undefined` when get the first array element?*
Javascript is a prototype-based scripting language and Array is an object, too.
-So if there is no property `0` in an array, the internal engine goes deeper to the prototype
+So if there is no property `0` in an array, the internal engine goes deeper to the prototype
and there is no such property in the prototype chain - return undefined.
When we try to access the value `0` property of array the internal method `[[GetProperty]]` gets called.
-If there is no such property `[[GetProperty]]` we try to get it from the prototype chain
+If there is no such property `[[GetProperty]]` we try to get it from the prototype chain
and `undefined` is returned if it stops on `null` (end of prototype chains).
diff --git a/src/shared/md/2014-03-13-String-Integers-Comparison.md b/src/shared/md/2014-03-13-String-Integers-Comparison.md
index 0b62202..ac90dac 100644
--- a/src/shared/md/2014-03-13-String-Integers-Comparison.md
+++ b/src/shared/md/2014-03-13-String-Integers-Comparison.md
@@ -1,15 +1,15 @@
-```javascript
+
"9" > "19" // true
"01" == "1" // false
-```
+
If you have accidently forgotten to parse integers, or you have a blind sort function for attributes, you might face this problem.
In JavaScript's string comparison, it takes the first character's code. So, what is really happening equivalent to:
-```javascript
+
"9".charCodeAt(0) > "19".charCodeAt(0) // 57 > 49 --> true
"01".charCodeAt(0) == "1".charCodeAt(0) // 48 == 49 --> false
-```
+
— [@rashad612](https://github.com/rashad612)
diff --git a/src/shared/md/2014-03-13-regex-test-true-false.md b/src/shared/md/2014-03-13-regex-test-true-false.md
index e329b58..66c7fec 100644
--- a/src/shared/md/2014-03-13-regex-test-true-false.md
+++ b/src/shared/md/2014-03-13-regex-test-true-false.md
@@ -1,5 +1,5 @@
-```
+
var re = new RegExp('Foo B', 'gi');
alert(re.test('Foo Bar')); // true
alert(re.test('Foo Bar')); // false
-```
\ No newline at end of file
+
diff --git a/src/shared/md/2014-05-05-this-length.md b/src/shared/md/2014-05-05-this-length.md
index 5c373c4..f6c2e69 100644
--- a/src/shared/md/2014-05-05-this-length.md
+++ b/src/shared/md/2014-05-05-this-length.md
@@ -1,5 +1,5 @@
-```
+
var foo = ["lval0", "lval1", "lval2", "lval3"];
foo[this.length] = "lval4";
foo[0]; //result same as foo.splice(0,1,"lval4"); =>lval4
-```
\ No newline at end of file
+
diff --git a/src/shared/md/2014-10-07-true-equals-false.md b/src/shared/md/2014-10-07-true-equals-false.md
index 75a26e5..f3e5e60 100644
--- a/src/shared/md/2014-10-07-true-equals-false.md
+++ b/src/shared/md/2014-10-07-true-equals-false.md
@@ -1,39 +1,39 @@
So, `!!` converts a value to a boolean and ensures a boolean type.
-```
+
!!false // --> false
!!true // --> true
-```
+
Ok, that makes sense. What about strings?
-```
+
!!"false" // --> true
!!"true" // --> true
-```
+
Weird. But wait, does this mean...
-```
+
!!"false" == !!"true" // --> true
-```
+
I bet if we also compare the type at least...
-```
+
!!"false" === !!"true" // --> true
-```
+
Then again...
-```
+
!!false == !!true // --> false
-```
+
..., but...
-```
+
!!"false" == !!true // --> true
!!"false" === !!true // --> true
-```
+
diff --git a/src/shared/md/2014-11-22-object-as-object-key.md b/src/shared/md/2014-11-22-object-as-object-key.md
index 5572dc9..e40917f 100644
--- a/src/shared/md/2014-11-22-object-as-object-key.md
+++ b/src/shared/md/2014-11-22-object-as-object-key.md
@@ -1,6 +1,6 @@
What happens when we set empty objects as keys:
-```
+
var result = (function() {
var foo = new Object();
var bar = new Object();
@@ -13,11 +13,11 @@ var result = (function() {
})();
console.log(result); // "bar"
-```
+
Explained:
-```
+
var result = (function() {
var foo = new Object(); // {}
var bar = new Object(); // {}
@@ -39,6 +39,6 @@ var result = (function() {
})();
console.log(result); // "bar"
-```
+
Thanks [Miguel Mota](http://www.miguelmota.com/).
diff --git a/src/shared/md/2015-02-02-Boolean-constructor.md b/src/shared/md/2015-02-02-Boolean-constructor.md
index 714fe2a..548158a 100644
--- a/src/shared/md/2015-02-02-Boolean-constructor.md
+++ b/src/shared/md/2015-02-02-Boolean-constructor.md
@@ -1,6 +1,6 @@
Why would you _ever_ use this function, or constructor, or ...?
-```
+
> Boolean(false)
false
> new Boolean(false)
@@ -15,7 +15,7 @@ true
{}
> if (new Boolean(false)) console.log('Indeed')
Indeed
-```
+
You couldn't _make_ this stuff up.
diff --git a/src/shared/md/2015-02-05-good-old-octal-decimal-wtf.md b/src/shared/md/2015-02-05-good-old-octal-decimal-wtf.md
index df6888a..39292b8 100644
--- a/src/shared/md/2015-02-05-good-old-octal-decimal-wtf.md
+++ b/src/shared/md/2015-02-05-good-old-octal-decimal-wtf.md
@@ -1,9 +1,9 @@
0-prefixed numbers are handled are automatically treated as octals. Or not.
-```
+
038 - 037 // 7 !?
037 // 31 thx to silent octal-to-decimal conversion
038 // 38 .. Silently switch to octal, silently fails to, and silently fallback to decimal
-```
+
Instead of throwing a SyntaxError (8 & 9 should be invalid characters),
octal mode silently switches to decimal if possible.
diff --git a/src/shared/md/2015-03-23-adding-arrays.md b/src/shared/md/2015-03-23-adding-arrays.md
index 19eb049..eb4d5f6 100644
--- a/src/shared/md/2015-03-23-adding-arrays.md
+++ b/src/shared/md/2015-03-23-adding-arrays.md
@@ -1,6 +1,6 @@
-```
+
[1, 2, 3] + [4, 5, 6] // "1,2,34,5,6"
-```
+
Being able to concatenate two comma-seperated strings without a comma in the middle is such a common use case. I'm glad the JS develpoers thought to optimise for the most common use case.
diff --git a/src/shared/md/2015-04-08-array-sort.md b/src/shared/md/2015-04-08-array-sort.md
index 22662e2..f8aa0eb 100644
--- a/src/shared/md/2015-04-08-array-sort.md
+++ b/src/shared/md/2015-04-08-array-sort.md
@@ -1,7 +1,7 @@
-```js
+
[1,2,3,15,30,7,5,45,60].sort()
// = [1,15,2,3,30,45,5,60,7]
-```
+
See [String Integers Comparison](https://wtfjs.com/wtfs/2014-03-13-String-Integers-Comparison) for the explanation.
diff --git a/src/shared/md/2015-04-16-moving-numbers.md b/src/shared/md/2015-04-16-moving-numbers.md
index 50fbcb6..f6c279a 100644
--- a/src/shared/md/2015-04-16-moving-numbers.md
+++ b/src/shared/md/2015-04-16-moving-numbers.md
@@ -1,5 +1,5 @@
Javascript numbers are facetious, sometimes they [play hide and seek](https://wtfjs.com/wtfs/2010-07-22-magic-increasing-number), sometimes they just won't obey:
-
+
1 << 32 // 1
-
+
diff --git a/src/shared/md/2015-04-23-screwy-negative-array-index.md b/src/shared/md/2015-04-23-screwy-negative-array-index.md
index 1a53f3f..16516e1 100644
--- a/src/shared/md/2015-04-23-screwy-negative-array-index.md
+++ b/src/shared/md/2015-04-23-screwy-negative-array-index.md
@@ -1,6 +1,6 @@
-```
+
var arr = [1, 2, 3, 4, 5, 6, 7, 8];
arr[-1] = "yo wazzzup";
console.log(arr.length); // > 8
console.log(arr[arr.indexOf(99)]); // log's > "yo wazzzup"
-```
+
diff --git a/src/shared/md/2016-03-09-Two-Special-Numbers.md b/src/shared/md/2016-03-09-Two-Special-Numbers.md
index 0fe96c2..83ec844 100644
--- a/src/shared/md/2016-03-09-Two-Special-Numbers.md
+++ b/src/shared/md/2016-03-09-Two-Special-Numbers.md
@@ -1,37 +1,37 @@
There seems to be a number that fulfills all of these conditions:
-```
+
i * i = 0
i + 1 = 1
i - 1 = -1
i / i = 1
-```
+
Turns out that this magical number is not even an integer:
-```
+
i = Number.MIN_VALUE
-```
+
It's the smallest possible fraction JavaScript can produce, and is treated as zero for the most part.
Conversely, the largest possible fraction claims to be greater than one, but reduces to zero:
-```
+
i = Number.MAX_VALUE
i > 1 // true
i|0 // 0
-```
+
Furthermore, both the largest possible fraction and integer refuse to wrap around:
-```
+
i = Number.MAX_VALUE
j = 0xffffffffffffffff
i === (i + 1) // true
j === (j + 1) // true
-```
+
– [@ionpot](https://github.com/ionpot)
diff --git a/src/shared/md/2016-03-10-Object-And-Array-Prototype-Length.md b/src/shared/md/2016-03-10-Object-And-Array-Prototype-Length.md
index bbd2ea6..f0bb0d4 100644
--- a/src/shared/md/2016-03-10-Object-And-Array-Prototype-Length.md
+++ b/src/shared/md/2016-03-10-Object-And-Array-Prototype-Length.md
@@ -1,8 +1,8 @@
-```javascript
+
Object.create(Array).length === 1 //true
-```
+
And
-```javascript
+
Object.keys(Object.create(Array)).length === 0 //true
-```
+
[@juliomatcom](https://github.com/juliomatcom)
diff --git a/src/shared/md/2016-03-19-weird-instanceof.md b/src/shared/md/2016-03-19-weird-instanceof.md
index 30bae11..88322eb 100644
--- a/src/shared/md/2016-03-19-weird-instanceof.md
+++ b/src/shared/md/2016-03-19-weird-instanceof.md
@@ -1,10 +1,10 @@
-```
+
function Test(){}
Test.prototype = null;
var a = new Test();
a instanceof Test; //Uncaught TypeError: Function has non-object prototype 'null' in instanceof check(…)
a instanceof Object; // true WTF?
-```
+
[ref](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof)
"The instanceof operator tests whether an object has in its prototype chain the prototype property of a constructor."
diff --git a/src/shared/md/2018-19-01-weird-number-addition.md b/src/shared/md/2018-19-01-weird-number-addition.md
index e2538ab..5772440 100644
--- a/src/shared/md/2018-19-01-weird-number-addition.md
+++ b/src/shared/md/2018-19-01-weird-number-addition.md
@@ -1,4 +1,4 @@
-```
+
console.log(.2+.1); // 0.30000000000000004
console.log(999999999999999999); // 1000000000000000000
console.log(true+true === 2); // true
@@ -6,6 +6,6 @@ console.log(true-true === 0); // true // So true must be 1 right ?
console.log(true === 1); // false
console.log('5' + 3); // 53
console.log('5' - 3); // 2
-```
+
[@Darth-koder007](https://github.com/@Darth-koder007)