"Strange" JavaScript Features

History

  • Mosaic -> Netscape
  • Java, Java applets
  • Mocha
  • Brendan Eich - "Scheme for the browser"
  • Time pressure (Sun deal)
  • Java, Scheme, Self
  • LiveScript -> JavaScript
  • Microsoft: JScript (DOM functions)
  • ES1 (1997), ES2-3, ES5, ES.next

Variables

  • Types?
  • Primitives
    • Undefined
    • Boolean
    • Number
    • String
    • Function
    • Null
  • Object

Variables

By reference vs. by value

Variables

var x = 1;
function f() {
    console.log(x);
    var x = 2;
}
f();

Variables

var vs. let

Asynch

console.log(1);
setTimeout(function(){
    console.log(2);
}, 0);
setTimeout(function(){
    console.log(3);
}, 1);
console.log(4);

Asynch

  1. Stack
  2. Web API
  3. Task queue
  4. Event loop
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");

Arrow functions

var obj = {
  i: 10,
  b: () => console.log(this.i, this),
  c: function() {
    console.log(this.i, this);
  }
}
obj.b();
obj.c();

Arrow functions

Clojures

function a(){
	var arr = [],
		i;
	for(i = 0; i < 5; i++) {
		arr.push(function(){
			console.log(i);
		});
	}
	return arr;
}
let x = arr();
x[2]();

OOP

class vs. prototype

instanceof

https://javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/

"Strange" JavaScript features

By Benedek Gagyi

"Strange" JavaScript features

  • 629