Benedek Gagyi
Web dev.
By reference vs. by value
var x = 1;
function f() {
console.log(x);
var x = 2;
}
f();
var vs. let
console.log(1);
setTimeout(function(){
console.log(2);
}, 0);
setTimeout(function(){
console.log(3);
}, 1);
console.log(4);
this
let x = {
y: 1,
z: function(){
console.log(this.y);
}
}
let tricky = x.z;
x.z();
tricky();
this
bind vs. call vs. apply
"A is for array, C is for comma."
var obj = {
x: function(message) {
console.log(message);
},
y: message => console.log(message)
}
obj.x("old school");
obj.y("new school");
var obj = {
i: 10,
b: () => console.log(this.i, this),
c: function() {
console.log(this.i, this);
}
}
obj.b();
obj.c();
function a(){
var arr = [],
i;
for(i = 0; i < 5; i++) {
arr.push(function(){
console.log(i);
});
}
return arr;
}
let x = arr();
x[2]();
class vs. prototype
instanceof
https://javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/
By Benedek Gagyi