beer in bottles?

beer in bottles

club-mate in bottles?

club-mate in bottles

milk in bottles?

milk in bottles

Objects (1)

var a = {};
a[{}] = [{}];
a[{}] == [{}];  false

Objects (2)

var a = {};
a[{}] = 1;
a[{}] == 1;  true

Comparison (1)

[]==[]  false

Comparison (2)

[]==[]
==[]==
[]==[]  true

Comparison (3)

false == []  true

Prototypes (1)

var X = function() {};
var y = new X();

y.constructor == X; true

Prototypes (2)

var X = function() {};
var y = new X();

X.prototype == y.prototype; false

Prototypes (3)

var X = function() {};
var y = new X();

X.prototype == y.__proto__; true

Prototypes (4)

var X = function() {};
var y = new X();

X.prototype.__proto__ == y.__proto__.__proto__; true

~~

~~7.5  7

Numbers & toString (1)

3.toString()  parse error

Numbers & toString (2)

3..toString()  "3"

Calculation

'5' + 3  '53'
'5' - 3  2

; (1)

return
{
    id : 1234,
    title : 'Tony the Pony'
};  parse error

return {
    id : 1234,
    title : 'Tony the Pony'
};  { ... }

return /*
*/{
  id : 1234,
  title : 'Tony the Pony'
};  { ... }

; (2)

Do we need a semicolon at the end?

var myFunction = function() {
  // ...
}

; (3)

Yes, if the next line starts with brackets:

var myFunction = function() {
  // ...
} // insert semicolon here
(function () {
  // ...
})();

Array length

var simpsons = ['Homer', 'Marge', 'Bart'];
simpsons[42] = 'Dr. Frink';
simpsons.length = ?  43

What’s the truth? (1)

''        == '0'           false
0         == ''            true
0         == '0'           true
false     == 'false'       false
false     == '0'           true
false     == undefined     false
false     == null          false
null      == undefined     true
" \t\r\n" == 0             true

What’s the truth? (2)

[[2]] ==    2   true
 [2]  ==   "2"  true
+[2]  == -"-2"  true
-[2]  == -"+2"  true

Awesome functions

o_O()

Parsing

parseInt('01')  1
parseInt('02')  2
parseInt('03')  3
parseInt('04')  4
parseInt('05')  5
parseInt('06')  6
parseInt('07')  7
parseInt('08')  0
parseInt('09')  0

false (1)

if (false) {
  
  alert("Hello World!");
  won’t be executed
}

false (2)

[0] == false  true

false (3)

if ([0]) {
  
  alert("Hello World!");
  will be executed
}

Valid syntax?

1 + + 1              2
1 + - + 1            0
1 + - + - + 1        2
1 + - + - + - + 1    0
1 + - + + + - + 1    2
1 + / + + + / + 1    1/ + + + /1
1 + / + / + / + 1    parse error

typeof

typeof 1   == ?  "number"

typeof "2" == ?  "string"

typeof NaN == ?  "number"

If
not a number
is
a number
you had too much
beer in bottles.

Or you’re coding JavaScript.

Thank you.