Skip to content

Instantly share code, notes, and snippets.

@bpinedah
bpinedah / typeof-weird.js
Created October 30, 2018 17:32
Understand js series
const fn = function() { return null; };
const nan = NaN;
console.log(typeof fn()); // object
console.log(typeof nan); // number :v
@bpinedah
bpinedah / typeof-example2.js
Created October 30, 2018 17:11
Understand js series
const fn = function() { return null; };
const arr = [];
const obj = {};
console.log(typeof fn); // function
console.log(typeof arr); // object
console.log(typeof obj); // object
@bpinedah
bpinedah / typeof-example.js
Last active October 30, 2018 16:52
Understand js series
const name = 'Bruce';
const age = 18;
const isDeveloper = true;
console.log(typeof name); // string
console.log(typeof age); // number
console.log(typeof isDeveloper); // boolean
@bpinedah
bpinedah / function-constructors-proto.js
Created October 28, 2018 08:01
Understand js series
function Person (name) {
console.log(this); // Person {}
this.name = name;
}
const bruce = new Person('Bruce');
console.log(bruce.__proto__); // Person {}
@bpinedah
bpinedah / function-constructors-error.js
Created October 28, 2018 07:47
Understand js series
function Person(){
this.name = 'Default';
}
const bruce = Person();
console.log(bruce.name); // TypeError: Cannot read property 'name' of undefined
@bpinedah
bpinedah / function-constructors.js
Created October 28, 2018 07:09
Understand js series
function Person() {
this.name = 'Default';
this.lastname = 'Default';
}
const bruce = new Person();
console.log(bruce);
@bpinedah
bpinedah / prototype-chain-function.js
Created October 28, 2018 06:15
Understand js series
const fn = function(){
// Do something
}
console.log(fn.__proto__.__proto__.__proto__); // null
@bpinedah
bpinedah / prototype-chain-zoom.js
Created October 28, 2018 06:04
Understand js series
const person = {
name: 'Anonymous',
lastname: 'Anonymous',
age: 18,
hair: true
}
const developer = {
languages: ['Javascript', 'C#', 'Java']
}
const esteban = {
@bpinedah
bpinedah / prototype-chain-example.js
Created October 28, 2018 05:27
Understand js series
const developer = {
name: 'Anonymous',
lastname: 'Anonymous',
fullname: function(){
return this.name + ' ' + this.lastname;
}
}
const bruce = {
name: 'Bruce',
lastname: 'Wayne'
@bpinedah
bpinedah / prototype-chain.js
Last active October 28, 2018 05:01
Understand js series
const fn = function(name){
console.log('hello ' + name);
}
const name = fn.name;
const fnCopy = fn.bind(this, 'Bruce');
fnCopy();
fn.call(this, 'Bruce');
fn.apply(this, ['Bruce']);
console.log(fn.toString());