diff --git a/README.md b/README.md
index c717c165..f19efb86 100644
--- a/README.md
+++ b/README.md
@@ -40,6 +40,8 @@ Thanks [Paul Irish](https://twitter.com/paul_irish) for the explanation.
Note that your code won't be highlighted :( If you'd like to figure out how to
get '```' to highlight, please help and submit PR! Thank you! - @DTrejo
+I might have figured highlighting out, but it requires further editing on your side - [paulstelian97](http://github.com/paulstelian97)
+
the code
---
diff --git a/src/html/get-wtfs-000wtfID/index.js b/src/html/get-wtfs-000wtfID/index.js
index 16923fb8..0db8a830 100644
--- a/src/html/get-wtfs-000wtfID/index.js
+++ b/src/html/get-wtfs-000wtfID/index.js
@@ -5,6 +5,21 @@ var exists = require('file-exists')
var arc = require('@architect/functions')
var layout = require('@wtfjs/theme')
+marked.setOptions({
+ renderer: new marked.Renderer(),
+ highlight: function(code) {
+ return require('highlight.js').highlightAuto(code).value;
+ },
+ pedantic: false,
+ gfm: true,
+ tables: true,
+ breaks: false,
+ sanitize: false,
+ smartLists: true,
+ smartypants: false,
+ xhtml: false
+});
+
function route(req, res) {
var filename = req.params.wtfID + '.md'
var filepath = path.join(__dirname, 'node_modules', '@wtfjs', 'md', filename)
diff --git a/src/md/2010-02-12-almost-but-not-quite.md b/src/md/2010-02-12-almost-but-not-quite.md
index 4ec77904..fde08080 100644
--- a/src/md/2010-02-12-almost-but-not-quite.md
+++ b/src/md/2010-02-12-almost-but-not-quite.md
@@ -1,3 +1,3 @@
-
- alert(111111111111111111111); // alerts 111111111111111110000
-
\ No newline at end of file
+``` javascript
+alert(111111111111111111111); // alerts 111111111111111110000
+```
diff --git a/src/md/2010-02-12-foonanny.md b/src/md/2010-02-12-foonanny.md
index aee780d1..9c5983d3 100644
--- a/src/md/2010-02-12-foonanny.md
+++ b/src/md/2010-02-12-foonanny.md
@@ -2,6 +2,6 @@ Evaluted as “foo” + (+ “bar”), which converts “bar” to not a number.
Proposal to rename this site: NaNwtf
-
- ("foo" + + "bar") === "fooNaN" // true
-
\ No newline at end of file
+``` javascript
+("foo" + + "bar") === "fooNaN" // true
+```
diff --git a/src/md/2010-02-12-function-context-fun.md b/src/md/2010-02-12-function-context-fun.md
index dea0f168..a2bc1dc9 100644
--- a/src/md/2010-02-12-function-context-fun.md
+++ b/src/md/2010-02-12-function-context-fun.md
@@ -1,6 +1,6 @@
-
+``` javascript
(x=[].reverse)() === window // 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/md/2010-02-12-maths-fun.md b/src/md/2010-02-12-maths-fun.md
index 456c4a8c..5c8f4e2c 100644
--- a/src/md/2010-02-12-maths-fun.md
+++ b/src/md/2010-02-12-maths-fun.md
@@ -1,7 +1,7 @@
Clearly JavaScript is not the most beautiful, or intuitive, language for maths.
-```
+``` javascript
typeof NaN === 'number' // true
Infinity === 1/0 // true
0.1 + 0.2 === 0.3 // false
-```
\ No newline at end of file
+```
diff --git a/src/md/2010-02-12-min-number-treachery.md b/src/md/2010-02-12-min-number-treachery.md
index c3ad0f0f..38d5ff71 100644
--- a/src/md/2010-02-12-min-number-treachery.md
+++ b/src/md/2010-02-12-min-number-treachery.md
@@ -1,6 +1,6 @@
-
- Number.MIN_VALUE > 0;
- // true? really? wtf.
-
+``` javascript
+Number.MIN_VALUE > 0;
+// true? really? wtf.
+```
-It turns out that MIN_VALUE is the smallest number GREATER THAN ZERO, which of course totally makes sense.
\ 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/md/2010-02-12-not-a-number-is-a-number.md b/src/md/2010-02-12-not-a-number-is-a-number.md
index 35502efb..771f24ce 100644
--- a/src/md/2010-02-12-not-a-number-is-a-number.md
+++ b/src/md/2010-02-12-not-a-number-is-a-number.md
@@ -1,5 +1,5 @@
-
- typeof NaN // number, of course.
-
+``` javascript
+typeof NaN // number, of course.
+```
-Now that makes sense.
\ No newline at end of file
+Now that makes sense.
diff --git a/src/md/2010-02-12-not-a-number-is-not-a-not-a-number.md b/src/md/2010-02-12-not-a-number-is-not-a-not-a-number.md
index ed5d517a..c043b2cf 100644
--- a/src/md/2010-02-12-not-a-number-is-not-a-not-a-number.md
+++ b/src/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.
-
+``` javascript
NaN === NaN // false
-
\ No newline at end of file
+```
diff --git a/src/md/2010-02-12-null-is-not-an-object.md b/src/md/2010-02-12-null-is-not-an-object.md
index b2baef91..593d427a 100644
--- a/src/md/2010-02-12-null-is-not-an-object.md
+++ b/src/md/2010-02-12-null-is-not-an-object.md
@@ -1,6 +1,6 @@
-```
+``` javascript
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/md/2010-02-12-parseint-treachery.md b/src/md/2010-02-12-parseint-treachery.md
index b67a69ce..e9767453 100644
--- a/src/md/2010-02-12-parseint-treachery.md
+++ b/src/md/2010-02-12-parseint-treachery.md
@@ -1,6 +1,6 @@
-```
+``` javascript
parseInt('06'); // 6
parseInt('08'); // 0
```
-This is because parseInt accepts a second argument for radix. If it is not supplied and the string starts with a 0 it will be parsed as an octal number. Riiiiiiight, of COURSE.
\ 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/md/2010-02-13-null-is-not-falsy.md b/src/md/2010-02-13-null-is-not-falsy.md
index 1b729bf1..01738543 100644
--- a/src/md/2010-02-13-null-is-not-falsy.md
+++ b/src/md/2010-02-13-null-is-not-falsy.md
@@ -1,5 +1,5 @@
-```
+``` javascript
[] == false; // true
"" == false; // true
null == false; // false, that's more like it
-```
\ No newline at end of file
+```
diff --git a/src/md/2010-02-13-string-is-not-string.md b/src/md/2010-02-13-string-is-not-string.md
index 8fd80e50..9fdb9ca8 100644
--- a/src/md/2010-02-13-string-is-not-string.md
+++ b/src/md/2010-02-13-string-is-not-string.md
@@ -1,7 +1,7 @@
-```
+``` javascript
"string" instanceof String; // false.
// 'course it isn't not a string, it may look like a string
// but actually it's masquerading as a banana.
```
-When is a string, not a string? When it’s a duck - [@rem](http://twitter.com/rem)
\ 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/md/2010-02-15-accidental-global.md b/src/md/2010-02-15-accidental-global.md
index 91de46ff..5e08657b 100644
--- a/src/md/2010-02-15-accidental-global.md
+++ b/src/md/2010-02-15-accidental-global.md
@@ -1,6 +1,6 @@
This one is fun and sneaky.
-```
+``` javascript
(function(){
var x = y = 1;
})();
@@ -8,4 +8,4 @@ This one is fun and sneaky.
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/md/2010-02-15-careful.md b/src/md/2010-02-15-careful.md
index 57ab0fb5..e3eeee58 100644
--- a/src/md/2010-02-15-careful.md
+++ b/src/md/2010-02-15-careful.md
@@ -1,5 +1,5 @@
-
- [] == ![] // true
-
+``` javascript
+[] == ![] // true
+```
-Arrays evaluate as true in a boolean condition so this does make some sense even if it doesn’t read very well! Thanks to [@collintmiller](http://twitter.com/collintmiller)!
\ 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/md/2010-02-15-coerce-equality.md b/src/md/2010-02-15-coerce-equality.md
index 36379243..23aa94d0 100644
--- a/src/md/2010-02-15-coerce-equality.md
+++ b/src/md/2010-02-15-coerce-equality.md
@@ -1,5 +1,5 @@
-
- 3 == "3" // true
-
+``` javascript
+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/md/2010-02-15-firebug-reserved.md b/src/md/2010-02-15-firebug-reserved.md
index 02098d4e..feb2eb8f 100644
--- a/src/md/2010-02-15-firebug-reserved.md
+++ b/src/md/2010-02-15-firebug-reserved.md
@@ -1,6 +1,6 @@
-```
+``` javascript
// whilst in firebug, try:
var console = {}; // or, well - anything actually...
```
-Firebug absolutely won’t let you create a variable called console, try and it’ll kick you in the happy sack - [@rem](http://twitter.com/rem)
\ 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/md/2010-02-15-hoisting.md b/src/md/2010-02-15-hoisting.md
index d8fee4ea..6d0bf5c7 100644
--- a/src/md/2010-02-15-hoisting.md
+++ b/src/md/2010-02-15-hoisting.md
@@ -1,8 +1,8 @@
-```
+``` javascript
(function(){
alert(window); // "undefined"
var window = window;
})();
```
-Because of “hoisting”, all variable *declarations* will be executed immediately at the top of a function scope. However, the variable *initializations* are not hoisted. So, local variable “window” is declared but uninitialized/”undefined”. wt-fun!
\ 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/md/2010-02-15-more-coerce-fun.md b/src/md/2010-02-15-more-coerce-fun.md
index eabca803..c9856052 100644
--- a/src/md/2010-02-15-more-coerce-fun.md
+++ b/src/md/2010-02-15-more-coerce-fun.md
@@ -1,7 +1,7 @@
-
- 3 == "03" // true!
-
+``` javascript
+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/md/2010-02-15-scope-fun.md b/src/md/2010-02-15-scope-fun.md
index 30a7f919..9ba3f537 100644
--- a/src/md/2010-02-15-scope-fun.md
+++ b/src/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…
-```
+``` javascript
Object.prototype.foo = 10;
console.log(foo); // 10
-```
\ No newline at end of file
+```
diff --git a/src/md/2010-02-15-thc-timetravel.md b/src/md/2010-02-15-thc-timetravel.md
index c9008f72..6ee2fb75 100644
--- a/src/md/2010-02-15-thc-timetravel.md
+++ b/src/md/2010-02-15-thc-timetravel.md
@@ -2,10 +2,10 @@
Woah!
-```
+``` javascript
var bignum = 1e300;
var ∞ = 1e400; //Infinity
alert(∞ - bignum); //Infinity
```
-Also note: [@sh1mmer](http://twitter.com/sh1mmer) is from the future wherein Unicode entities are valid for variable identifiers. Rename above to something sane in our old school present day interpreters.
\ 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/md/2010-02-15-timeout-delay.md b/src/md/2010-02-15-timeout-delay.md
index 9b824ae0..67ff4e8d 100644
--- a/src/md/2010-02-15-timeout-delay.md
+++ b/src/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.
-```
+``` javascript
// for FF only
setTimeout(function(rand){ alert(rand); },10); // FF passes a "magic" param we call "rand"
for (var i=0; i<100000; i++) { i; } // take some time
-```
\ No newline at end of file
+```
diff --git a/src/md/2010-02-15-true-has-a-value.md b/src/md/2010-02-15-true-has-a-value.md
index 3a39f626..25a50b90 100644
--- a/src/md/2010-02-15-true-has-a-value.md
+++ b/src/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.
-```
+``` javascript
(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/md/2010-02-15-undefined-is-mutable.md b/src/md/2010-02-15-undefined-is-mutable.md
index 19baacff..c9b21eff 100644
--- a/src/md/2010-02-15-undefined-is-mutable.md
+++ b/src/md/2010-02-15-undefined-is-mutable.md
@@ -1,6 +1,6 @@
In JavaScript, undefined is nothing but a global variable name without a default value. Therefore, its primitive value is undefined. You can change the value of undefined:
-```
+``` javascript
var a = {};
a.b === undefined; // true because property b is not set
undefined = 42;
@@ -9,9 +9,9 @@ In JavaScript, undefined is nothing but a global variable name without a default
Due to the mutability of undefined, it is generally a better idea to check for undefined-ness through typeof:
-```
+``` javascript
var a = {};
typeof a.b == 'undefined'; // always true
```
-– [@mathias](http://mathiasbynens.be/)
\ No newline at end of file
+– [@mathias](http://mathiasbynens.be/)
diff --git a/src/md/2010-02-16-automagic-semicolons.md b/src/md/2010-02-16-automagic-semicolons.md
index 41b67112..192fb9f7 100644
--- a/src/md/2010-02-16-automagic-semicolons.md
+++ b/src/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?
-```
+``` javascript
function laugh()
{
return
@@ -10,4 +10,4 @@ I’m certain that this will end all debate about where curly braces belong… r
}
laugh();
// returns undefined
-```
\ No newline at end of file
+```
diff --git a/src/md/2010-02-16-more-floating-point-rounding.md b/src/md/2010-02-16-more-floating-point-rounding.md
index 1a1a924c..9ee279d4 100644
--- a/src/md/2010-02-16-more-floating-point-rounding.md
+++ b/src/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)
-```
+``` javascript
// 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/md/2010-02-16-reserved-for-future-use-maybe.md b/src/md/2010-02-16-reserved-for-future-use-maybe.md
index bd931365..6a4754a4 100644
--- a/src/md/2010-02-16-reserved-for-future-use-maybe.md
+++ b/src/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.
-```
+``` javascript
// In Safari, try...
var enum;
//-> SyntaxError: Parse error
-```
\ No newline at end of file
+```
diff --git a/src/md/2010-02-19-concat-coerce.md b/src/md/2010-02-19-concat-coerce.md
index 323c769a..dd92cfaf 100644
--- a/src/md/2010-02-19-concat-coerce.md
+++ b/src/md/2010-02-19-concat-coerce.md
@@ -1,7 +1,7 @@
More concat “fun”.
-```
+``` javascript
"3" + 1 // '31'
"3" - 1 // 2
"222" - -"111" // 333 (⊙﹏⊙)
-```
\ No newline at end of file
+```
diff --git a/src/md/2010-02-23-arguing-with-arguments.md b/src/md/2010-02-23-arguing-with-arguments.md
index d94eecef..0a81fcce 100644
--- a/src/md/2010-02-23-arguing-with-arguments.md
+++ b/src/md/2010-02-23-arguing-with-arguments.md
@@ -1,6 +1,6 @@
Nice arguments hackery going on here.
-```
+``` javascript
(function(a,b,c) {
print(a,b,c); // one two three
print(arguments[0], arguments[1], arguments[2]); // one two three
@@ -20,7 +20,7 @@ Nice arguments hackery going on here.
}
```
-```
+``` javascript
// A more real world example:
(function(arg1, arg2) {
print(arg1, arg2);
@@ -31,4 +31,4 @@ Nice arguments hackery going on here.
})('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/md/2010-02-23-boolean-paradox.md b/src/md/2010-02-23-boolean-paradox.md
index 7cfef38e..c3a03edf 100644
--- a/src/md/2010-02-23-boolean-paradox.md
+++ b/src/md/2010-02-23-boolean-paradox.md
@@ -1,7 +1,7 @@
Boolean logic paradox via [@amattie](amattie)!
-```
+``` javascript
"0" && {} // true
0 && {} // false, ok...fair enough
0 == "0" // true, wtf!
-```
\ No newline at end of file
+```
diff --git a/src/md/2010-02-23-coerced.md b/src/md/2010-02-23-coerced.md
index 1c1335ed..3dd25527 100644
--- a/src/md/2010-02-23-coerced.md
+++ b/src/md/2010-02-23-coerced.md
@@ -1,5 +1,5 @@
Careful w/ number type coercion! Thanks [@kelemen_viktor](http://twitter.com/kelemen_viktor)!
-
+``` javascript
a = 012 // 10
-
\ No newline at end of file
+```
diff --git a/src/md/2010-02-23-declaration-vs-initialization.md b/src/md/2010-02-23-declaration-vs-initialization.md
index a3cbbc39..4671c86c 100644
--- a/src/md/2010-02-23-declaration-vs-initialization.md
+++ b/src/md/2010-02-23-declaration-vs-initialization.md
@@ -1,4 +1,4 @@
-```
+``` javascript
var a = 8;
var someFunc = function(){
document.write(a);
@@ -7,4 +7,4 @@
someFunc(); // writes undefined
```
-Of course, the variable is undefined because its being declared but not initialized until after the document.write in the function context which itself runs before the first declaration of a. Yowza. Cheers to [Boaz, Al & Rick](http://weblog.bocoup.com/weird-var-behavior-in-javascript) for this one!
\ 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/md/2010-02-23-makes-perfect-sense.md b/src/md/2010-02-23-makes-perfect-sense.md
index 4d9e564c..d8e946a3 100644
--- a/src/md/2010-02-23-makes-perfect-sense.md
+++ b/src/md/2010-02-23-makes-perfect-sense.md
@@ -1,7 +1,7 @@
Ha! This one is great.
-
+``` javascript
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/md/2010-02-24-messing-with-number-prototype.md b/src/md/2010-02-24-messing-with-number-prototype.md
index b8b5b122..dabff830 100644
--- a/src/md/2010-02-24-messing-with-number-prototype.md
+++ b/src/md/2010-02-24-messing-with-number-prototype.md
@@ -1,6 +1,6 @@
[@rcanine](http://twitter.com/rcanine) shows us this interesting this coerce behaviour within the prototype of Number. Fun!
-```
+``` javascript
(1) === 1; // true
Number.prototype.isOne = function () { return this === 1; }
@@ -10,4 +10,4 @@
Number.prototype.reallyIsOne = function () { return this - 1 === 0; }
(1).reallyIsOne(); // true
-```
\ No newline at end of file
+```
diff --git a/src/md/2010-02-25-ie-and-webkit-agree.md b/src/md/2010-02-25-ie-and-webkit-agree.md
index 019a3341..5114cb55 100644
--- a/src/md/2010-02-25-ie-and-webkit-agree.md
+++ b/src/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)!
-```
+``` javascript
(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/md/2010-02-25-jsftw b/src/md/2010-02-25-jsftw
deleted file mode 100644
index e69de29b..00000000
diff --git a/src/md/2010-02-25-jsftw:-google-closure-compiler.md b/src/md/2010-02-25-jsftw:-google-closure-compiler.md
index 1162d47b..10a2713b 100644
--- a/src/md/2010-02-25-jsftw:-google-closure-compiler.md
+++ b/src/md/2010-02-25-jsftw:-google-closure-compiler.md
@@ -1,6 +1,6 @@
-
+``` javascript
// 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/md/2010-02-26-array-crazy.md b/src/md/2010-02-26-array-crazy.md
index 182265de..ed23f809 100644
--- a/src/md/2010-02-26-array-crazy.md
+++ b/src/md/2010-02-26-array-crazy.md
@@ -1,6 +1,6 @@
Plausible code:
-```
+``` javascript
[] == 0 // true
+[] === 0 // true, wait whu?
++[] === 1 // sorta, though this is invalid js syntax, so...
@@ -8,7 +8,7 @@ Plausible code:
Somewhat unlikely and, lets be honest, regrettable code:
-```
+``` javascript
[[]][0] === []
++[[]][0] === 1
++[[]][+[]] === 1 // yay! wtf!
diff --git a/src/md/2010-02-26-implicit-tostring-fun.md b/src/md/2010-02-26-implicit-tostring-fun.md
index c3edc446..54fb65a6 100644
--- a/src/md/2010-02-26-implicit-tostring-fun.md
+++ b/src/md/2010-02-26-implicit-tostring-fun.md
@@ -1,6 +1,6 @@
Be careful with those implicit .toString() calls in == comparisons.
-```
+``` javascript
typeof "abc" == "string" // true
typeof String("abc") == "string" // true
String("abc") == "abc" // true -- same types get casted to equal each other
@@ -8,10 +8,10 @@ Be careful with those implicit .toString() calls in == comparisons.
Also, instantiation via the _new_ operator can yield interesting results!
-```
+``` javascript
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/md/2010-03-02-ie-cursed-recursion.md b/src/md/2010-03-02-ie-cursed-recursion.md
index a4668b7a..bf4b966d 100644
--- a/src/md/2010-03-02-ie-cursed-recursion.md
+++ b/src/md/2010-03-02-ie-cursed-recursion.md
@@ -1,4 +1,4 @@
-```
+``` javascript
window.recurse = function(times) {
if (times !== 0)
recurse(times - 1);
diff --git a/src/md/2010-03-04-max-vs-the-infinite.md b/src/md/2010-03-04-max-vs-the-infinite.md
index 1de2ef2c..109de789 100644
--- a/src/md/2010-03-04-max-vs-the-infinite.md
+++ b/src/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.
-```
+``` javascript
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/md/2010-04-02-object-to-primitive-coerce.md b/src/md/2010-04-02-object-to-primitive-coerce.md
index 98e58d39..3a3e9ab6 100644
--- a/src/md/2010-04-02-object-to-primitive-coerce.md
+++ b/src/md/2010-04-02-object-to-primitive-coerce.md
@@ -1,4 +1,4 @@
-```
+``` javascript
var foo = {
toString: function () {
return 5;
@@ -12,4 +12,4 @@
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/md/2010-04-12-call-in-ur-call.md b/src/md/2010-04-12-call-in-ur-call.md
index 5fcd661c..f1b6f5f3 100644
--- a/src/md/2010-04-12-call-in-ur-call.md
+++ b/src/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.
-
+``` javascript
alert.call.call.call.call.call.apply(function (a) {return a}, [1,2]) // 2
-
\ No newline at end of file
+```
diff --git a/src/md/2010-04-16-build-your-own-wtfjs.md b/src/md/2010-04-16-build-your-own-wtfjs.md
index a7fe70a0..7a8229c1 100644
--- a/src/md/2010-04-16-build-your-own-wtfjs.md
+++ b/src/md/2010-04-16-build-your-own-wtfjs.md
@@ -1,6 +1,6 @@
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.
-```
+``` shell
$ git clone git@github.com:brianleroux/wtfjs.git
$ cd wtfjs/
$ heroku create --stack beech
diff --git a/src/md/2010-04-16-contributing-to-wtfjs.md b/src/md/2010-04-16-contributing-to-wtfjs.md
index 2a3ad563..48d1bb51 100644
--- a/src/md/2010-04-16-contributing-to-wtfjs.md
+++ b/src/md/2010-04-16-contributing-to-wtfjs.md
@@ -17,4 +17,4 @@ Maybe you found a bug or something is driving you crazy. Perhaps you want to giv
either way
---
-[Fork it.](http://github.com/brianleroux/wtfjs) Send a pull request. Don't forget to add yourself as a committer to the /about page.
\ No newline at end of file
+[Fork it.](http://github.com/brianleroux/wtfjs) Send a pull request. Don't forget to add yourself as a committer to the /about page.
diff --git a/src/md/2010-04-16-express-js-gotcha.md b/src/md/2010-04-16-express-js-gotcha.md
index a966e71f..489eba04 100644
--- a/src/md/2010-04-16-express-js-gotcha.md
+++ b/src/md/2010-04-16-express-js-gotcha.md
@@ -1,6 +1,6 @@
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:
-```
+``` javascript
configure(function() {
set("root", __dirname);
// allow static file serving from public directory
@@ -8,4 +8,4 @@ Less of a wtf and more of a gotcha. In [ExpressJS](http://expressjs.com/). you
});
```
-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/md/2010-04-17-global-scope-mindtricks.md b/src/md/2010-04-17-global-scope-mindtricks.md
index 4101e388..e4385fc6 100644
--- a/src/md/2010-04-17-global-scope-mindtricks.md
+++ b/src/md/2010-04-17-global-scope-mindtricks.md
@@ -2,14 +2,14 @@ An update by [@deadlyicon](http://twitter.com/deadlyicon) on the previous post.
This is just a really silly way of saying this:
-```
+``` javascript
Function.prototype.call.apply(function (a) {return a}, [1,2])
// 2
```
If this still seems weird to you. Consider this:
-```
+``` javascript
function logThisAndArgs() {
console.log(this, arguments);
};
@@ -19,7 +19,7 @@ If this still seems weird to you. Consider this:
Now this!
-```
+``` javascript
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/md/2010-04-30-operators-and-regexp-fun.md b/src/md/2010-04-30-operators-and-regexp-fun.md
index a89c796c..f1fa649e 100644
--- a/src/md/2010-04-30-operators-and-regexp-fun.md
+++ b/src/md/2010-04-30-operators-and-regexp-fun.md
@@ -1,6 +1,6 @@
[@ThomasFuchs](http://twitter.com/thomasfuchs) throws down this obfuscated beauty:
-```
+``` javascript
1 + + 1 // => 2
1 + - + 1 // => 0
1 + - + - + 1 // => 2
@@ -9,4 +9,4 @@
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/md/2010-04-31-isNaN.md b/src/md/2010-04-31-isNaN.md
index dfb92b80..9b618c84 100644
--- a/src/md/2010-04-31-isNaN.md
+++ b/src/md/2010-04-31-isNaN.md
@@ -1,6 +1,6 @@
So, [null is not an object](https://wtfjs.com/wtfs/2010-02-12-null-is-not-an-object) though sometimes null is a Number.
-```
+``` javascript
isNaN( null ); // false
null === NaN; // false
null == NaN; // false
@@ -8,9 +8,9 @@ So, [null is not an object](https://wtfjs.com/wtfs/2010-02-12-null-is-not-an-obj
isNaN converts null to number.
-
+``` javascript
Number( null ); // 0
-
+```
But WTF. :) - [@oleg008](http://twitter.com/oleg008)
-
\ No newline at end of file
+
diff --git a/src/md/2010-04-31-syntax-highlighting-serverside-with-google-prettyfy.md b/src/md/2010-04-31-syntax-highlighting-serverside-with-google-prettyfy.md
index 6b7de2a1..9c2942a8 100644
--- a/src/md/2010-04-31-syntax-highlighting-serverside-with-google-prettyfy.md
+++ b/src/md/2010-04-31-syntax-highlighting-serverside-with-google-prettyfy.md
@@ -2,11 +2,11 @@ This is much more awesome. I have to thank the guys at [HowToNode.org](http://ho
The only remaining problem with the syntax highlighting is now nested <code> elements have to be escaped to display correctly in the final render.
-```
+``` javascript
// 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/md/2010-06-02-instances-and-default-values.md b/src/md/2010-06-02-instances-and-default-values.md
index 4edebf27..395815fa 100644
--- a/src/md/2010-06-02-instances-and-default-values.md
+++ b/src/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`.
-```
+``` javascript
var a = new Number;
a == 0 // true
@@ -16,7 +16,7 @@ When you create instances of `String` or `Number`, they take the default value (
This is even more confusing when using the JSON-style syntax to create objects and arrays.
-```
+``` javascript
var a = {};
a == {} // false
@@ -26,4 +26,9 @@ This is even more confusing when using the JSON-style syntax to create objects a
-- [@remi](http://twitter.com/remi)
-(Never forget: [====](http://crockfordfacts.com/MHDTvKwy3xGzI183Akuh_Q) - [@brianleroux](http://twitter.com/brianleroux))
\ No newline at end of file
+This is because `==` comparisons will compare references if both sides are of an object type (arrays are also objects); since they are two different references, they will compare unequal. That is, `==` is the same as `===` when you work with objects and arrays.
+
+-- [paulstelian97](http://github.com/paulstelian97)
+
+
+(Never forget: [====](http://crockfordfacts.com/MHDTvKwy3xGzI183Akuh_Q) - [@brianleroux](http://twitter.com/brianleroux))
diff --git a/src/md/2010-06-08-void-is-a-black-hole.md b/src/md/2010-06-08-void-is-a-black-hole.md
index cc631a9d..e4f0fea8 100644
--- a/src/md/2010-06-08-void-is-a-black-hole.md
+++ b/src/md/2010-06-08-void-is-a-black-hole.md
@@ -1,8 +1,8 @@
Void is a blackhole...
-```
+``` javascript
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/md/2010-06-09-function-in-ur-string.md b/src/md/2010-06-09-function-in-ur-string.md
index b64d9dbf..66e59e0a 100644
--- a/src/md/2010-06-09-function-in-ur-string.md
+++ b/src/md/2010-06-09-function-in-ur-string.md
@@ -1,6 +1,6 @@
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.
-```
+``` javascript
var Z = "constructor";
Z[Z][Z]("alert('wtfjs!')")();
// alerts wtfjs!
@@ -8,7 +8,7 @@ Old friend (_and clearly damaged by a career of JavaScript programming_) [@jaked
Ok. So wtf exactly is happening here?
-```
+``` javascript
Z[Z]
// function String() { [native code] }
@@ -18,11 +18,11 @@ Ok. So wtf exactly is happening here?
AHA! The constructor property of a string is `String` and the constructor property of `String` is `Function`. Makes sense.
-```
+``` javascript
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/md/2010-07-11-length-of-what-now.md b/src/md/2010-07-11-length-of-what-now.md
index d19ca0bb..42b1e946 100644
--- a/src/md/2010-07-11-length-of-what-now.md
+++ b/src/md/2010-07-11-length-of-what-now.md
@@ -1,13 +1,13 @@
This made me laugh. Out loud even!
-```
+``` javascript
console.log((!+[]+[]+![]).length);
// 9
```
Huh, wtf?! Lets see what we're getting the length of...
-```
+``` javascript
console.log((!+[]+[]+![]));
// "truefalse"
```
diff --git a/src/md/2010-07-12-fail.md b/src/md/2010-07-12-fail.md
index 9cde4433..bfaf5675 100644
--- a/src/md/2010-07-12-fail.md
+++ b/src/md/2010-07-12-fail.md
@@ -1,26 +1,26 @@
Let's take the last post a step further:
-```
+``` javascript
console.log( (![]+[])[+[]]+(![]+[])[+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]] ) // "fail"
```
Breaking that mass of symbols into pieces we notices, that the following patten occurs often:
-```
+``` javascript
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:
-```
+``` javascript
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:
-```
+``` javascript
console.log( [+[]] ) // [ 0]
console.log( +[] ) // 0
```
@@ -29,4 +29,4 @@ Thinking of a `String` as an `Array` we can access its first character via `[0]`
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/md/2010-07-22-magic-increasing-number.md b/src/md/2010-07-22-magic-increasing-number.md
index 88fa9167..a1aa5764 100644
--- a/src/md/2010-07-22-magic-increasing-number.md
+++ b/src/md/2010-07-22-magic-increasing-number.md
@@ -1,9 +1,9 @@
Look at me, I'm the magic increasing number!
-```
+``` javascript
9999999999999999
//=> 10000000000000000
```
---- [@thomasfuchs](http://twitter.com/thomasfuchs)
\ No newline at end of file
+--- [@thomasfuchs](http://twitter.com/thomasfuchs)
diff --git a/src/md/2010-07-23-im-not-a-number-really.md b/src/md/2010-07-23-im-not-a-number-really.md
index 283cb251..18789810 100644
--- a/src/md/2010-07-23-im-not-a-number-really.md
+++ b/src/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.
-
+``` javascript
typeof NaN
//=> number
-
+```
--- [@3rdEden](http://twitter.com/3rdEden)
Its still hilarious. Now, check this out:
-
+``` javascript
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/md/2010-09-16-eval-changes.md b/src/md/2010-09-16-eval-changes.md
index bb2beafd..10e5e1bc 100644
--- a/src/md/2010-09-16-eval-changes.md
+++ b/src/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
-
+``` javascript
[foo("foo=2"),foo]
-
+```
and take that path with me.
Tested on chrome, firefox, opera, and safari.
@@ -12,7 +12,7 @@ Tested on chrome, firefox, opera, and safari.
#### Apparently eval is evil.
Doesn't seem so evil.
-```
+``` javascript
function foo(x){var foo=1;eval(x);return foo;};
//[2,function foo(x){var foo=1;eval(x);return foo;}]
@@ -21,7 +21,7 @@ Doesn't seem so evil.
#### Apparently assigning eval to a variable changes how it acts. WTF.
...Ok I can deal with that I guess.
-```
+``` javascript
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/md/2010-10-15-ie-754.md b/src/md/2010-10-15-ie-754.md
index 31b043b0..700a692d 100644
--- a/src/md/2010-10-15-ie-754.md
+++ b/src/md/2010-10-15-ie-754.md
@@ -1,6 +1,6 @@
You wouldn't believe me...
-```
+``` javascript
ie-754
//=> -754
```
diff --git a/src/md/2010-11-10-false-advertising.md b/src/md/2010-11-10-false-advertising.md
index c3469a20..0977e81e 100644
--- a/src/md/2010-11-10-false-advertising.md
+++ b/src/md/2010-11-10-false-advertising.md
@@ -1,6 +1,6 @@
What do you think this constructor returns for `new Dude('Bob')`? Doug or Bob?
-```
+``` javascript
function Dude(name){
this.name = name;
return {name: 'Doug'};
@@ -8,7 +8,7 @@ What do you think this constructor returns for `new Dude('Bob')`? Doug or Bob?
```
Answer:
-```
+``` javascript
var bob = new Dude('Bob');
// { name: 'Doug' }
bob instanceof Dude
@@ -16,7 +16,7 @@ Answer:
```
Huh!? So you can just slip in anything? What about arrays?
-```
+``` javascript
function Dude(name){
this.name = name;
return [1, 2, 3];
@@ -26,7 +26,7 @@ Huh!? So you can just slip in anything? What about arrays?
```
That can't be! What about...
-```
+``` javascript
function Dude(name){
this.name = name;
return 3;
@@ -37,4 +37,4 @@ That can't be! What about...
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/md/2010-11-15-i-am-myself-but-also-not-myself.md b/src/md/2010-11-15-i-am-myself-but-also-not-myself.md
index cca61a7c..c83da8fc 100644
--- a/src/md/2010-11-15-i-am-myself-but-also-not-myself.md
+++ b/src/md/2010-11-15-i-am-myself-but-also-not-myself.md
@@ -1,6 +1,6 @@
Sometimes JavaScript has identity crisis:
-```
+``` javascript
var foo = [0];
console.log(foo == !foo);
console.log(foo == foo);
@@ -9,3 +9,10 @@ console.log(foo == foo);
Is it time to have a "maybe" operator? :-P
--- [@diogobaeder](http://twitter.com/diogobaeder)
+
+This happens due to the type coercions done in the two expressions.
+In the first expression, !foo is ! applied to a non-empty array; that ends up `!true`, or `false`. This means `foo == false`. OK, now an array with a single element can decay to its element in boolean conversions, so `[0] == false` is true.
+
+In the second expression, you compare two Array references, and they are equal references, so `==` is the same as `===` and they both return `true`.
+
+--- [paulstelian97](http://github.com/paulstelian97)
diff --git a/src/md/2010-12-06-convert-to-integer.md b/src/md/2010-12-06-convert-to-integer.md
index ccb54190..cf6d8d1a 100755
--- a/src/md/2010-12-06-convert-to-integer.md
+++ b/src/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.
-```
+``` javascript
function toInt(number) {
return number && + number | 0 || 0;
}
diff --git a/src/md/2011-02-11-all-your-commas-are-belong-to-Array.md b/src/md/2011-02-11-all-your-commas-are-belong-to-Array.md
index dcc0eb92..c0d2599f 100644
--- a/src/md/2011-02-11-all-your-commas-are-belong-to-Array.md
+++ b/src/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:
-
+``` javascript
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:
-```
+``` javascript
Array.prototype.join = function (separator) {
var result = "";
if ("undefined" === typeof separator) {
@@ -70,9 +70,9 @@ respective `ToPrimitive` methods ask for `[[DefaultValue]]` with String as the t
Another similar WTF on the same topic:
-
+``` javascript
",,," == 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
-
+``` javascript
[undefined,undefined,undefined,undefined].join(),
-
+```
Which yields something like:
-
+``` javascript
"" + 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:
-
+``` javascript
",,," == Array((null,'cool',false,NaN,4)); // true
-
+```
If this doesn't make you WTF, I'm not sure what will.
diff --git a/src/md/2011-05-12-parseInt-is-not-eval.md b/src/md/2011-05-12-parseInt-is-not-eval.md
index 49051bb4..12ef6c21 100644
--- a/src/md/2011-05-12-parseInt-is-not-eval.md
+++ b/src/md/2011-05-12-parseInt-is-not-eval.md
@@ -1,13 +1,13 @@
Remember folks, parseInt() is not eval().
-```
+``` javascript
parseInt("1", 10); // 1
eval("1") // 1
```
Pretty much the same thing....wait.
-```
+``` javascript
parseInt("1 + 1", 10); // 1
eval("1 + 1") // 2
```
@@ -15,7 +15,7 @@ Pretty much the same thing....wait.
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.
-```
+``` javascript
parseInt("1 - 1", 10); // 1
eval("1 - 1") // 0
```
@@ -23,14 +23,14 @@ eval() at least gets it right.
The string example takes the first digit and just throws out the rest of the string.
And again, eval() with the correct solution.
-```
+``` javascript
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.
-```
+``` javascript
parseInt("1" - "1", 10); // 0
eval ("1" - "1") // 0
```
diff --git a/src/md/2011-06-23-parseint-magic.md b/src/md/2011-06-23-parseint-magic.md
index b2736d27..d29410de 100644
--- a/src/md/2011-06-23-parseint-magic.md
+++ b/src/md/2011-06-23-parseint-magic.md
@@ -1,8 +1,8 @@
Be aware of parseInt!
-
+``` javascript
parseInt(null, 24) === 23 // true
-
+```
[Answer and source!](http://stackoverflow.com/q/6459758/269804)
diff --git a/src/md/2011-07-26-iteration-demoralization.md b/src/md/2011-07-26-iteration-demoralization.md
index 49226259..a634dd3e 100644
--- a/src/md/2011-07-26-iteration-demoralization.md
+++ b/src/md/2011-07-26-iteration-demoralization.md
@@ -1,6 +1,6 @@
See if you can guess what this will output:
-```
+``` javascript
function allNames() {
var names = [ 'dan', 'anthony', 'pavel' ];
for (name in names) {
@@ -22,9 +22,9 @@ If you guessed this:
What you might not have guessed, is what this will output:
-
+``` javascript
console.log(window.name);
-
+```
it's:
@@ -35,7 +35,7 @@ Iteration is assignment, and without the use of the `var` keyword, you're really
So the original function is equivalent to:
-```
+``` javascript
function allNames() {
var names = [ 'dan', 'anthony', 'pavel' ];
for (window.name in names) {
diff --git a/src/md/2011-09-24-Date-silently-accepts-anything.md b/src/md/2011-09-24-Date-silently-accepts-anything.md
index aa02346e..bcbfb8be 100644
--- a/src/md/2011-09-24-Date-silently-accepts-anything.md
+++ b/src/md/2011-09-24-Date-silently-accepts-anything.md
@@ -1,4 +1,4 @@
-```
+``` javascript
d = new Date("couldn't you please throw an exception here instead?");
// No! You get the joy of discovering this error somewhere unrelated,
diff --git a/src/md/2011-11-08-undefined-identity-crisis.md b/src/md/2011-11-08-undefined-identity-crisis.md
index ba413e02..99f74ad8 100644
--- a/src/md/2011-11-08-undefined-identity-crisis.md
+++ b/src/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?
-```
+``` javascript
function test (a) {
if (undefined = a) {
a = {}
diff --git a/src/md/2011-11-11-the-universe-answers-and-JavaScript-still-makes-us-wtf.md b/src/md/2011-11-11-the-universe-answers-and-JavaScript-still-makes-us-wtf.md
index cfac9a1b..fe72aae3 100644
--- a/src/md/2011-11-11-the-universe-answers-and-JavaScript-still-makes-us-wtf.md
+++ b/src/md/2011-11-11-the-universe-answers-and-JavaScript-still-makes-us-wtf.md
@@ -4,7 +4,7 @@ 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:
-```
+``` javascript
// is there an error (if not, what do I return?)
"3" -+-+-+ "1" + "1" / "3" * "6" + "2"
```
@@ -20,7 +20,7 @@ than that, aren't we?).
The precedence of operators in JavaScript are (from highest to lowest):
-```
+``` javascript
delete
void
typeof
@@ -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:
-```
+``` javascript
+
"2" +
@@ -138,7 +138,7 @@ evaluated, we have:
However, we don't know what types are implicitly cast yet. Let's make another
tree showing non-ambiguous operations (`/`, `*`, `-`):
-```
+``` javascript
+
"2" +
@@ -154,7 +154,7 @@ 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:
-```
+``` javascript
+
"2" 4
@@ -165,7 +165,7 @@ 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
-```
+``` javascript
"42"
```
diff --git a/src/md/2011-12-16-negative-zero-equal-but-not-equal.md b/src/md/2011-12-16-negative-zero-equal-but-not-equal.md
index d5f901a2..90fe6bc4 100644
--- a/src/md/2011-12-16-negative-zero-equal-but-not-equal.md
+++ b/src/md/2011-12-16-negative-zero-equal-but-not-equal.md
@@ -1,4 +1,4 @@
-```
+``` javascript
0 === -0 //true
1/0 === 1/-0 //false
```
diff --git a/src/md/2012-04-18-changing-variables-changes-arguments.md b/src/md/2012-04-18-changing-variables-changes-arguments.md
index 8cec419f..c5889abc 100644
--- a/src/md/2012-04-18-changing-variables-changes-arguments.md
+++ b/src/md/2012-04-18-changing-variables-changes-arguments.md
@@ -1,7 +1,7 @@
It turns out that changing the value of an argument variable will change its
value in the `arguments` "array":
-```
+``` javascript
> function hello(what) {
. what = "world";
. return "Hello, " + arguments[0] + "!";
diff --git a/src/md/2012-05-07-Numbers-and-dots.md b/src/md/2012-05-07-Numbers-and-dots.md
index b6f1780c..263b8c75 100644
--- a/src/md/2012-05-07-Numbers-and-dots.md
+++ b/src/md/2012-05-07-Numbers-and-dots.md
@@ -1,6 +1,6 @@
A JavaScript syntax oddity with Numbers and Dots:
-```
+``` javascript
// Ok, you may have seen wrapping a number literal with parens to call Number methods
(42).toFixed(2); // "42.00"
diff --git a/src/md/2012-08-11-Slashes!.md b/src/md/2012-08-11-Slashes!.md
index d582ecd9..f739698b 100644
--- a/src/md/2012-08-11-Slashes!.md
+++ b/src/md/2012-08-11-Slashes!.md
@@ -1,6 +1,6 @@
What should the following JS yield?
-```
+``` javascript
n = 1
/1*"\/\//.test(n + '"//')
```
@@ -9,7 +9,7 @@ Should it be `true`? (It is `NaN`.)
Using semicolons, on the other hand, makes it behave like you'd expect:
-```
+``` javascript
n = 1;
/1*"\/\//.test(n + '"//');
```
@@ -35,7 +35,7 @@ concatenation.
An interesting variation that shows what happens more clearly is the following:
-```
+``` javascript
n = 1
/1?":n\/\//.test(n + '":n//')
```
@@ -46,7 +46,7 @@ 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:
-```
+``` javascript
n = 0
/0?":n\/\//.test(n + '":n//')
```
diff --git a/src/md/2012-09-19-Hexadecimal-weirdness.md b/src/md/2012-09-19-Hexadecimal-weirdness.md
index 3207b4a7..489b1fba 100644
--- a/src/md/2012-09-19-Hexadecimal-weirdness.md
+++ b/src/md/2012-09-19-Hexadecimal-weirdness.md
@@ -1,20 +1,20 @@
In JS you can represent numbers in hexadecimal, right?
-
+``` javascript
var hex = 0xFF55;
-
+```
You can also perform shift operations, right?
Left shift is equivalent to a multiplication...
-```
+``` javascript
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
-```
+``` javascript
// Before 0x800000 it's ok
alert((0x777777 << 8).toString(16)); // 0x77777700
@@ -44,7 +44,7 @@ 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:
-```
+``` javascript
0x888888 * 0x100 === 8947848.0 * 256.0 === 2290649088.0
```
diff --git a/src/md/2012-10-10-infinity-madness.md b/src/md/2012-10-10-infinity-madness.md
index 8d00f809..d87c702e 100644
--- a/src/md/2012-10-10-infinity-madness.md
+++ b/src/md/2012-10-10-infinity-madness.md
@@ -1,4 +1,4 @@
-```js
+```javascript
parseFloat( 'Infinity' ) // returns Infinity
Number( 'Infinity' ) // returns Infinity
parseInt( 'Infinity' ) // returns NaN
@@ -7,7 +7,7 @@
But of course, you should always specify a radix when calling `parseInt`:
-```js
+```javascript
parseInt( 'Infinity', 10 ) // returns NaN
// ...
parseInt( 'Infinity', 18 ) // returns NaN...
diff --git a/src/md/2012-12-28-undefined-props-on-numbers.md b/src/md/2012-12-28-undefined-props-on-numbers.md
index 80d15172..2cf83220 100644
--- a/src/md/2012-12-28-undefined-props-on-numbers.md
+++ b/src/md/2012-12-28-undefined-props-on-numbers.md
@@ -1,4 +1,4 @@
-```
+``` javascript
function getBounds(node) {
var n = node || 0;
return { width: n.width, height: n.height };
diff --git a/src/md/2013-01-28-array-comparison.md b/src/md/2013-01-28-array-comparison.md
index 1f755e64..4079aa6d 100644
--- a/src/md/2013-01-28-array-comparison.md
+++ b/src/md/2013-01-28-array-comparison.md
@@ -1,13 +1,13 @@
Did you know that JavaScript can compare arrays using lexicographical ordering?
-```
+``` javascript
[1, 2, 4] < [1, 2, 5] // true
[1, 3, 4] < [1, 2, 5] // false
```
Just don't expect trichotomy to hold.
-```
+``` javascript
[1, 2, 3] === [1, 2, 3] // false
[1, 2, 3] < [1, 2, 3] // false
[1, 2, 3] == [1, 2, 3] // false
@@ -16,7 +16,7 @@ Just don't expect trichotomy to hold.
Oh, and just in case you're wondering, it knows it's messing with you.
-```
+``` javascript
[1, 2, 3] <= [1, 2, 3] // true
[1, 2, 3] >= [1, 2, 3] // true
```
@@ -37,7 +37,7 @@ return the result of the comparison ToPrimitive(x) == y.
10.Return false.
-```
+``` javascript
[] === []; // false
[] == []; // false
@@ -55,7 +55,7 @@ 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.
-```
+``` javascript
[] < []; // false
[] > []; // false
// its like 1 < 1 ==> false and 1 > 1 ==> false
@@ -66,7 +66,7 @@ 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.
-```
+``` javascript
[] <= []; // true
[] >= []; // true
// its like 1 <= 1 ==> true and 1 >= 1 ==> true
diff --git a/src/md/2013-02-05-magic-function-properties.md b/src/md/2013-02-05-magic-function-properties.md
index ee718523..bdb90aa4 100644
--- a/src/md/2013-02-05-magic-function-properties.md
+++ b/src/md/2013-02-05-magic-function-properties.md
@@ -1,11 +1,11 @@
-```
+``` javascript
var f = function() { };
f.foo = 'foo'; // sets f.foo to 'foo'
```
Functions are objects, so you can set properties on them after creation.
-```
+``` javascript
f.name; // is ''
f.name = 'foo';
f.name; // is still ''
@@ -13,7 +13,7 @@ Functions are objects, so you can set properties on them after creation.
But not all the time.
-```
+``` javascript
var f = function myFunction() { };
f.name; // is 'myFunction'
```
diff --git a/src/md/2013-02-12-obfuscated-fibonacci.md b/src/md/2013-02-12-obfuscated-fibonacci.md
index e1985aa3..048820ca 100644
--- a/src/md/2013-02-12-obfuscated-fibonacci.md
+++ b/src/md/2013-02-12-obfuscated-fibonacci.md
@@ -1,4 +1,4 @@
-```
+``` javascript
var fib = function (_) {
for(_=[+[],++[[]][+[]],+[],_],_[++[++[++[[]][+[]]][+[]]][+[]]]=(((_[++[++[++[[]][+[]]][+[]]][+[]]]-(++[[]][+[]]))&(((--[[]][+[]])>>>(++[[]][+[]]))))===(_[++[++[++[[]][+[]]][+[]]][+[]]]-(++[[]][+[]])))?(_[++[++[[]][+[]]][+[]]]=++[[]][+[]],_[++[++[++[[]][+[]]][+[]]][+[]]]-(++[[]][+[]])):+[];_[++[++[++[[]][+[]]][+[]]][+[]]]--;_[+[]]=(_[++[[]][+[]]]=_[++[++[[]][+[]]][+[]]]=_[+[]]+_[++[[]][+[]]])-_[+[]]);
return _[++[++[[]][+[]]][+[]]];
diff --git a/src/md/2013-02-13-unicode-vars.md b/src/md/2013-02-13-unicode-vars.md
index 9c2e728c..685dddfa 100644
--- a/src/md/2013-02-13-unicode-vars.md
+++ b/src/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:
-```
+``` javascript
var \u1000 = {
\u1001: 'foo',
\u1011: 'bar'
diff --git a/src/md/2013-02-21-why-am-i-a-number.md b/src/md/2013-02-21-why-am-i-a-number.md
index 56d49747..4200c00c 100644
--- a/src/md/2013-02-21-why-am-i-a-number.md
+++ b/src/md/2013-02-21-why-am-i-a-number.md
@@ -1,6 +1,6 @@
Can someone tell me?
-```
+``` javascript
"Why am I a " + typeof + ""; // "Why am I a number"
```
@@ -15,7 +15,7 @@ can be used as an unary operator (syntax is: + UnaryExpression). + converts its
Note that we can cast strings to numbers by preceding them with +:
-```
+``` javascript
(2 + "3"); // 23
(2 + +"3"); // 5
@@ -29,7 +29,7 @@ Note that we can cast strings to numbers by preceding them with +:
***
-```
+``` javascript
typeof +""; // number
// even
diff --git a/src/md/2013-02-22-parseint-radix.md b/src/md/2013-02-22-parseint-radix.md
index e196d782..d2920dfe 100644
--- a/src/md/2013-02-22-parseint-radix.md
+++ b/src/md/2013-02-22-parseint-radix.md
@@ -1,4 +1,4 @@
-```
+``` javascript
parseInt('fuck'); // NaN
parseInt('fuck', 16); // 15
```
@@ -11,7 +11,7 @@ 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:
-```
+``` javascript
parseInt('3fucks') // 3
parseInt('3fucks', 16) // 3f in hex = 63
```
diff --git a/src/md/2013-02-28-null,-undefined-and-test.md b/src/md/2013-02-28-null,-undefined-and-test.md
index 1296d766..d7b91ff8 100644
--- a/src/md/2013-02-28-null,-undefined-and-test.md
+++ b/src/md/2013-02-28-null,-undefined-and-test.md
@@ -2,7 +2,7 @@ Checking a variable for one word with one to ten letters lowercase only?
Try this regular expression: `/^[a-z]{1,10}$/.test('wakaluba')`.
-```
+``` javascript
/^[a-z]{1,10}$/.test(null);
/^[a-z]{1,10}$/.test(undefined);
```
@@ -13,7 +13,7 @@ Both should obviously fail, but return **true**. srsly, WTF JS?
This happens because regex.test() converts its parameter to a string:
-```
+``` javascript
String(null) // "null"
```
diff --git a/src/md/2013-03-06-false-isnt-false.md b/src/md/2013-03-06-false-isnt-false.md
index 5581fb78..892567fa 100644
--- a/src/md/2013-03-06-false-isnt-false.md
+++ b/src/md/2013-03-06-false-isnt-false.md
@@ -1,4 +1,4 @@
-```
+``` javascript
true == 'true' // true
false == 'false'; // false
```
diff --git a/src/md/2013-03-25-null-to-bool.md b/src/md/2013-03-25-null-to-bool.md
index b451494d..1541b898 100644
--- a/src/md/2013-03-25-null-to-bool.md
+++ b/src/md/2013-03-25-null-to-bool.md
@@ -1,10 +1,10 @@
-```
+``` javascript
null == false // false
```
Okay, we know this. Null doesn't convert to boolean.
Now try this...
-```
+``` javascript
!null // true
```
@@ -14,7 +14,7 @@ Well, this is awkward.
The issue here is that Null **can** be converted to a boolean, it just
isn't **implicitly** converted:
-```
+``` javascript
Boolean(null) // false
```
diff --git a/src/md/2013-03-27-automatic-semicolon-insertion.md b/src/md/2013-03-27-automatic-semicolon-insertion.md
index 7699c6a6..7f35e6fe 100644
--- a/src/md/2013-03-27-automatic-semicolon-insertion.md
+++ b/src/md/2013-03-27-automatic-semicolon-insertion.md
@@ -1,6 +1,6 @@
This is another case of an accidental global:
-```
+``` javascript
var a = 1
b = 1;
diff --git a/src/md/2013-04-18-true-story-bro.md b/src/md/2013-04-18-true-story-bro.md
index a30f39aa..12ee6c1c 100644
--- a/src/md/2013-04-18-true-story-bro.md
+++ b/src/md/2013-04-18-true-story-bro.md
@@ -1,8 +1,8 @@
True story bro!
-
+``` javascript
'true' == true // returns false
-
+```
— [ProfessorWeb][1]
diff --git a/src/md/2013-04-28-isfinite-null-is-true.md b/src/md/2013-04-28-isfinite-null-is-true.md
index 42c6036a..faec0a2d 100644
--- a/src/md/2013-04-28-isfinite-null-is-true.md
+++ b/src/md/2013-04-28-isfinite-null-is-true.md
@@ -1,6 +1,6 @@
`isFinite` function of JavaScript tests whether a number is finite.
-```
+``` javascript
isFinite(42); // true
isFinite(1/0); // false
isFinite(0/0); // NaN is not finite -> false
@@ -10,14 +10,14 @@
These are normal results.
-```
+``` javascript
isFinite(); // false
isFinite(undefined); // false
```
Undefined values are not finite. These are normal results too.
-```
+``` javascript
isFinite(null); // true
```
diff --git a/src/md/2013-06-20-negative-indexes.md b/src/md/2013-06-20-negative-indexes.md
index 5ff9a9f2..942c8f8e 100644
--- a/src/md/2013-06-20-negative-indexes.md
+++ b/src/md/2013-06-20-negative-indexes.md
@@ -1,6 +1,6 @@
Negative numbers mean different things to different functions on the Array prototype.
-```
+``` javascript
var nums = [1, 2, 3];
nums.splice(nums.indexOf('wtf'), 1);
nums; // [1, 2]
@@ -13,7 +13,7 @@ Interestingly, negative numbers put inside Array.Splice splice the item that is
e.g.
-```
+``` javascript
var nums = [1, 2, 3, 4, 5];
nums.splice(-1, 1); // removes the last item
nums.splice(-2, 1); // removes the second last item
@@ -23,7 +23,7 @@ until.......
you reach the start of your array - afterwards, the first item will always be the item spliced:
-```
+``` javascript
var nums = [1, 2, 3];
nums.splice(-12, 1);
nums; // [2, 3]
diff --git a/src/md/2013-07-04-array-constructor.md b/src/md/2013-07-04-array-constructor.md
index 6997bc7f..58bfd9bb 100644
--- a/src/md/2013-07-04-array-constructor.md
+++ b/src/md/2013-07-04-array-constructor.md
@@ -1,4 +1,4 @@
-```
+``` javascript
Array(20).map(function(elem) { return 'a'; }); // Array of undefined x 20
```
diff --git a/src/md/2013-08-07-Math.max()-behaviour.md b/src/md/2013-08-07-Math.max()-behaviour.md
index cd0838c2..4a61687a 100644
--- a/src/md/2013-08-07-Math.max()-behaviour.md
+++ b/src/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.
-```
+``` javascript
Math.max(3, 0); // 3
Math.max(3, {}); // NaN
Math.max(3, []); // 3
@@ -13,7 +13,7 @@ types** in different ways.
Now, let's focus on **Booleans**:
-```
+``` javascript
Math.max(1, true); // 1
Math.max(0, true); // 1
Math.max(1, false); // 1
@@ -23,7 +23,7 @@ Now, let's focus on **Booleans**:
And now, on **Arrays**:
-```
+``` javascript
Math.max(-1, []); // 0
Math.max(-1, [1]); // 1
Math.max(-1, [1, 4]); // NaN
diff --git a/src/md/2013-09-30-Array-Constructor2-is-Very-Undefined.md b/src/md/2013-09-30-Array-Constructor2-is-Very-Undefined.md
index c630a945..701a9471 100644
--- a/src/md/2013-09-30-Array-Constructor2-is-Very-Undefined.md
+++ b/src/md/2013-09-30-Array-Constructor2-is-Very-Undefined.md
@@ -2,11 +2,11 @@ Have you ever thought that `Array(3)` will return you an array of 3 `undefined`'
the same as `[undefined,undefined,undefined]`?
So try this:
-```
+``` javascript
Array(3).forEach(function(elem) { console.log(elem); });
```
And you will get no result at all, however
-```
+``` javascript
[undefined,undefined,undefined].forEach(function(elem) { console.log(elem); });
```
will give you 3 nice log entries.
diff --git a/src/md/2013-10-07-Local-storage-limitations.md b/src/md/2013-10-07-Local-storage-limitations.md
index 231e5f9d..83be6f4f 100644
--- a/src/md/2013-10-07-Local-storage-limitations.md
+++ b/src/md/2013-10-07-Local-storage-limitations.md
@@ -1,7 +1,7 @@
The **local storage** functionality in browsers is a bit limited and this can
lead to some rather surprising behaviour.
-```
+``` javascript
localStorage[0] = false;
if (localStorage[0]) {
diff --git a/src/md/2013-12-15-charAt-is-not-the-same-as-[].md b/src/md/2013-12-15-charAt-is-not-the-same-as-%5B%5D.md
similarity index 94%
rename from src/md/2013-12-15-charAt-is-not-the-same-as-[].md
rename to src/md/2013-12-15-charAt-is-not-the-same-as-%5B%5D.md
index 337fd82a..2b1f44fc 100644
--- a/src/md/2013-12-15-charAt-is-not-the-same-as-[].md
+++ b/src/md/2013-12-15-charAt-is-not-the-same-as-%5B%5D.md
@@ -1,12 +1,12 @@
In case someone tells you it doesn't matter how you access characters in strings, they're wrong:
-
+``` javascript
'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/md/2013-12-19-The-Hungry-Variable.md b/src/md/2013-12-19-The-Hungry-Variable.md
index 6d77f447..7022bb49 100644
--- a/src/md/2013-12-19-The-Hungry-Variable.md
+++ b/src/md/2013-12-19-The-Hungry-Variable.md
@@ -1,5 +1,5 @@
Consider this JS:
-```
+``` javascript
x = /[/ + "javascript"[0] + '///'
```
What do you expect the value of `x` to be?
@@ -7,7 +7,7 @@ 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:
-```
+``` javascript
"/[/j///"
```
@@ -27,7 +27,7 @@ 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:
-```
+``` javascript
/(/
//SyntaxError: Invalid regular expression: /(/: Unterminated group
@@ -53,7 +53,7 @@ the `//'` is simply a comment.
If you want the pre to do as expected, add a single forward slash before the
first "[":
-```
+``` javascript
x = /\[/ + "javascript"[0] + '///'
"/\[/j///"
diff --git a/src/md/2014-01-11-multiplying-arrays-and-objects.md b/src/md/2014-01-11-multiplying-arrays-and-objects.md
index cce71576..a1bbdfb1 100644
--- a/src/md/2014-01-11-multiplying-arrays-and-objects.md
+++ b/src/md/2014-01-11-multiplying-arrays-and-objects.md
@@ -1,10 +1,10 @@
-
+``` javascript
[4] * [4] // 16
[] * [] // 0
[] * {} // NaN
[4, 4] * [4, 4] // NaN
({} * {}) // NaN
-
+```
— [@Tobiaqs][1]
[1]:https://github.com/Tobiaqs
diff --git a/src/md/2014-01-29-regular-expression-and-slash.md b/src/md/2014-01-29-regular-expression-and-slash.md
index 42929d50..38778b39 100644
--- a/src/md/2014-01-29-regular-expression-and-slash.md
+++ b/src/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:
-```
+``` javascript
/[A-Z]/.test("A"); // true
/[A-Z]/.test("b"); // false
/[A-Z]/.test("Z"); // true
@@ -15,7 +15,7 @@ comes doing some test:
The weird thing comes when I do this test:
-```
+``` javascript
/[A-z]/.test("A"); // true
/[A-z]/.test("a"); // true
/[A-z]/.test("Z"); // true
diff --git a/src/md/2014-02-04-Date.Date-vs-Year.md b/src/md/2014-02-04-Date.Date-vs-Year.md
index 167b7f15..a8c61b4c 100644
--- a/src/md/2014-02-04-Date.Date-vs-Year.md
+++ b/src/md/2014-02-04-Date.Date-vs-Year.md
@@ -1,6 +1,6 @@
`Date.getDate()` returns the day of the Month, whereas `Date.getMonth()` returns the previous month (somehow *zero-indexed*).
-```
+``` javascript
var date = new Date('Tue Apr 01 2014')
date // Tue Apr 01 2014 00:00:00 GMT+0200
date.getDate() // 1
diff --git a/src/md/2014-02-20-math-pow.md b/src/md/2014-02-20-math-pow.md
index 74218908..b0b723cc 100644
--- a/src/md/2014-02-20-math-pow.md
+++ b/src/md/2014-02-20-math-pow.md
@@ -1,33 +1,33 @@
[The spec of ECMAScript](http://ecma-international.org/ecma-262/5.1/#sec-15.8.2.13) specifies some default values of `Math.pow`.
-```
+``` javascript
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)
-```
+``` javascript
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`).
-```
+``` javascript
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...
-```
+``` javascript
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...
-```
+``` javascript
console.log(Math.pow(1, Infinity)); // NaN
```
diff --git a/src/md/2014-02-22-wtf_document.all.md b/src/md/2014-02-22-wtf_document.all.md
index 69bb2dfd..3fbc99ae 100644
--- a/src/md/2014-02-22-wtf_document.all.md
+++ b/src/md/2014-02-22-wtf_document.all.md
@@ -1,9 +1,9 @@
In Chrome
-```
+``` javascript
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/md/2014-02-25-array-indexof.md b/src/md/2014-02-25-array-indexof.md
index 79a47728..7735ed3d 100644
--- a/src/md/2014-02-25-array-indexof.md
+++ b/src/md/2014-02-25-array-indexof.md
@@ -1,5 +1,5 @@
**Not empty array doesn't contain its element:**
-```
+``` javascript
var a = [,];
a.length; //1, some element exists
a.indexOf(a[0]); //-1
@@ -11,7 +11,7 @@ a.indexOf(a[0]); //-1
`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):
-```
+``` javascript
Elided array elements are not defined.
...
The missing array element contributes to the length of the Array and increases the index of subsequent elements.
@@ -19,7 +19,7 @@ The missing array element contributes to the length of the Array and increases t
Elements are not `undefined`, they are `not initialized`.
When we invoke `indexOf` on an array this is one of the steps that happens:
-```
+``` javascript
Let kPresent be the result of calling the [[HasProperty]] internal method of O with argument ToString(k).
```
diff --git a/src/md/2014-03-13-regex-test-true-false.md b/src/md/2014-03-13-regex-test-true-false.md
index e329b585..5bb2b544 100644
--- a/src/md/2014-03-13-regex-test-true-false.md
+++ b/src/md/2014-03-13-regex-test-true-false.md
@@ -1,5 +1,5 @@
-```
+``` javascript
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/md/2014-05-05-this-length.md b/src/md/2014-05-05-this-length.md
index 5c373c4e..7c9277b0 100644
--- a/src/md/2014-05-05-this-length.md
+++ b/src/md/2014-05-05-this-length.md
@@ -1,5 +1,5 @@
-```
+``` javascript
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/md/2014-10-07-true-equals-false.md b/src/md/2014-10-07-true-equals-false.md
index 75a26e5e..dd24a2e8 100644
--- a/src/md/2014-10-07-true-equals-false.md
+++ b/src/md/2014-10-07-true-equals-false.md
@@ -1,39 +1,39 @@
So, `!!` converts a value to a boolean and ensures a boolean type.
-```
+``` javascript
!!false // --> false
!!true // --> true
```
Ok, that makes sense. What about strings?
-```
+``` javascript
!!"false" // --> true
!!"true" // --> true
```
Weird. But wait, does this mean...
-```
+``` javascript
!!"false" == !!"true" // --> true
```
I bet if we also compare the type at least...
-```
+``` javascript
!!"false" === !!"true" // --> true
```
Then again...
-```
+``` javascript
!!false == !!true // --> false
```
..., but...
-```
+``` javascript
!!"false" == !!true // --> true
!!"false" === !!true // --> true
```
diff --git a/src/md/2014-11-22-object-as-object-key.md b/src/md/2014-11-22-object-as-object-key.md
index 5572dc9a..1abe99f6 100644
--- a/src/md/2014-11-22-object-as-object-key.md
+++ b/src/md/2014-11-22-object-as-object-key.md
@@ -1,6 +1,6 @@
What happens when we set empty objects as keys:
-```
+``` javascript
var result = (function() {
var foo = new Object();
var bar = new Object();
@@ -17,7 +17,7 @@ console.log(result); // "bar"
Explained:
-```
+``` javascript
var result = (function() {
var foo = new Object(); // {}
var bar = new Object(); // {}
diff --git a/src/md/2015-02-02-Boolean-constructor.md b/src/md/2015-02-02-Boolean-constructor.md
index 714fe2a6..e3b26614 100644
--- a/src/md/2015-02-02-Boolean-constructor.md
+++ b/src/md/2015-02-02-Boolean-constructor.md
@@ -1,6 +1,6 @@
Why would you _ever_ use this function, or constructor, or ...?
-```
+``` javascript
> Boolean(false)
false
> new Boolean(false)
diff --git a/src/md/2015-02-05-good-old-octal-decimal-wtf.md b/src/md/2015-02-05-good-old-octal-decimal-wtf.md
index df6888aa..ea6ceed4 100644
--- a/src/md/2015-02-05-good-old-octal-decimal-wtf.md
+++ b/src/md/2015-02-05-good-old-octal-decimal-wtf.md
@@ -1,5 +1,5 @@
0-prefixed numbers are handled are automatically treated as octals. Or not.
-```
+``` javascript
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
diff --git a/src/md/2015-03-23-adding-arrays.md b/src/md/2015-03-23-adding-arrays.md
index 19eb049b..12797be9 100644
--- a/src/md/2015-03-23-adding-arrays.md
+++ b/src/md/2015-03-23-adding-arrays.md
@@ -1,4 +1,4 @@
-```
+``` javascript
[1, 2, 3] + [4, 5, 6] // "1,2,34,5,6"
```
diff --git a/src/md/2015-04-08-array-sort.md b/src/md/2015-04-08-array-sort.md
index 22662e2f..9415706b 100644
--- a/src/md/2015-04-08-array-sort.md
+++ b/src/md/2015-04-08-array-sort.md
@@ -1,4 +1,4 @@
-```js
+```javascript
[1,2,3,15,30,7,5,45,60].sort()
// = [1,15,2,3,30,45,5,60,7]
```
diff --git a/src/md/2015-04-16-moving-numbers.md b/src/md/2015-04-16-moving-numbers.md
index 50fbcb69..e96915a2 100644
--- a/src/md/2015-04-16-moving-numbers.md
+++ b/src/md/2015-04-16-moving-numbers.md
@@ -1,5 +1,11 @@
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:
-
+``` javascript
1 << 32 // 1
-
+```
+
+--- please fill in the OP of this one
+
+Left shifting in Javascript works with 32 bit integers, so the number 1 is converted to the 32 bit integer 1, then left shifted by the processor by 0 (a quirk makes it only take the lowest 5 bits of the shift amount, so shifting by 32 is the same as shifting by 0, or not shifting at all) then converted back to the Javascript numeric type.
+
+--- [paulstelian97](http://github.com/paulstelian97)
diff --git a/src/md/2015-04-23-screwy-negative-array-index.md b/src/md/2015-04-23-screwy-negative-array-index.md
index 1a53f3f4..959f5e1b 100644
--- a/src/md/2015-04-23-screwy-negative-array-index.md
+++ b/src/md/2015-04-23-screwy-negative-array-index.md
@@ -1,4 +1,4 @@
-```
+``` javascript
var arr = [1, 2, 3, 4, 5, 6, 7, 8];
arr[-1] = "yo wazzzup";
console.log(arr.length); // > 8
diff --git a/src/md/2016-03-09-Two-Special-Numbers.md b/src/md/2016-03-09-Two-Special-Numbers.md
index 0fe96c2e..943d1db1 100644
--- a/src/md/2016-03-09-Two-Special-Numbers.md
+++ b/src/md/2016-03-09-Two-Special-Numbers.md
@@ -1,6 +1,6 @@
There seems to be a number that fulfills all of these conditions:
-```
+``` javascript
i * i = 0
i + 1 = 1
i - 1 = -1
@@ -9,7 +9,7 @@ There seems to be a number that fulfills all of these conditions:
Turns out that this magical number is not even an integer:
-```
+``` javascript
i = Number.MIN_VALUE
```
@@ -17,7 +17,7 @@ It's the smallest possible fraction JavaScript can produce, and is treated as ze
Conversely, the largest possible fraction claims to be greater than one, but reduces to zero:
-```
+``` javascript
i = Number.MAX_VALUE
i > 1 // true
@@ -26,7 +26,7 @@ Conversely, the largest possible fraction claims to be greater than one, but red
Furthermore, both the largest possible fraction and integer refuse to wrap around:
-```
+``` javascript
i = Number.MAX_VALUE
j = 0xffffffffffffffff
diff --git a/src/md/2016-03-19-weird-instanceof.md b/src/md/2016-03-19-weird-instanceof.md
index 30bae11e..00ce5b1d 100644
--- a/src/md/2016-03-19-weird-instanceof.md
+++ b/src/md/2016-03-19-weird-instanceof.md
@@ -1,4 +1,4 @@
-```
+``` javascript
function Test(){}
Test.prototype = null;
var a = new Test();
diff --git a/src/md/2018-19-01-wierd-number-addition.md b/src/md/2018-19-01-wierd-number-addition.md
index e2538ab8..0e79dee2 100644
--- a/src/md/2018-19-01-wierd-number-addition.md
+++ b/src/md/2018-19-01-wierd-number-addition.md
@@ -1,4 +1,4 @@
-```
+``` javascript
console.log(.2+.1); // 0.30000000000000004
console.log(999999999999999999); // 1000000000000000000
console.log(true+true === 2); // true