Skip to main content

you don't know JS

  •  “==“ vs “==="
  • Coercion
  • Does not compare underlying values of functions, arrays, objects
  • Values that are default falsy, everything is truthy
  • “"
  • 0, -0, NaN
  • null
  • undefined
  • false
  • Hoisting - concept where you call a function before it is created
var a = 2;
foo(); // works because \`foo()\` declaration is "hoisted"
function foo() {
a = 3;
console.log( a ); // 3
var a; // declaration is "hoisted" to the top of \`foo()\`
}
console.log( a ); // 2
  • Functions as a value
var foo = function() {
// ..
};
var x = function bar(){
// ..
};

The first function

  • Strict mode prevents hoisting
  • this refers to where the function is executed
function foo() {
console.log( this.bar );
}

var bar = "global";
var obj1 = {
bar: "obj1",
foo: foo
};
var obj2 = {
bar: "obj2"
};
// -------
foo(); //gloal
obj1.foo(); // "obj1"
foo.call( obj2 ); // "obj2"
new foo(); // undefined