Last active
July 22, 2021 08:12
-
-
Save Buggytheclown/561bb151952ea0a08dc5b309dd138bbb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// *** Variables, Hoisting, Closures *** | |
// *Understanding of scope* | |
(function () {})(); | |
(function () { | |
for (var vari = 5; vari > 0; vari--) {} | |
for (let leti = 5; leti > 0; --leti) {} | |
{ | |
const consti = 5; | |
} | |
console.assert(myEq([vari, leti, consti]), [0, 0, 5]); | |
})(); | |
// *Understanding of hoisting* | |
(function () { | |
let test = 'outer'; | |
someFunction(); | |
const test2 = 'outer2'; | |
function someFunction() { | |
console.assert(test === 'outer'); | |
console.assert(test2 === 'outer2'); | |
var test = 'inner'; | |
} | |
})(); | |
// *Closure* | |
(function () { | |
var array = [1, 2, 3, 4]; | |
for (var index = 0; index < array.length; index++) { | |
setTimeout(function () { | |
console.assert(typeof array[index] === 'number'); | |
}, 0); | |
} | |
})(); | |
// *let vs const vs var* | |
// ??? | |
// *Context* | |
(function () { | |
var bob = { | |
name: 'Bob', | |
// sayName: () => { | |
sayName: function () { | |
return this.name; | |
}, | |
}; | |
var alice = { | |
name: 'Alice', | |
}; | |
var bobSayName = bob.sayName; | |
console.assert(bobSayName() === 'Bob'); // 1 | |
alice.bobSayName = bobSayName; | |
console.assert(alice.bobSayName() === 'Alice'); // 2 | |
console.assert(bobSayName.call(alice) === 'Alice'); // 3 | |
console.assert(bobSayName.bind(bob).call(alice) === 'Alice'); // 4 | |
})(); | |
// *** Knowledge of the Dom Events *** | |
// *Capturing* | |
// *Bubbling* | |
// *Event Delegation* | |
// *PreventDefault, stopPropagation, stopImmediatePropagation* | |
// *addEventListener* | |
// Open link and complete tasks - https://stackblitz.com/edit/rs-dom-events?file=index.js | |
// *** Knowledge of the Event Loop *** | |
// *What is Event Loop* | |
// *Promises & Microtasks* | |
(function () { | |
var stack = []; | |
stack.push(1); | |
setTimeout(() => stack.push(2), 1000); | |
setTimeout(() => stack.push(3), 0); | |
Promise.resolve(4).then(stack.push.bind(stack)); | |
stack.push(5); | |
setTimeout(() => { | |
console.assert(myEq(stack, [1, 2, 3, 4, 5])); | |
}, 5000); | |
})(); | |
(function () { | |
const stack = []; | |
new Promise(function (res, rej) { | |
throw 'My-Exeption'; | |
}) | |
.catch(function (ex) { | |
stack.push('catched'); | |
}) | |
.then( | |
function (res) { | |
stack.push('then'); | |
}, | |
function (rej) { | |
stack.push('catched'); | |
}, | |
); | |
setTimeout(() => console.assert(myEq(stack, ['catched', 'catched'])), 1000); | |
})(); | |
// *Knowledge of inheritance and classes* | |
/* | |
// Fix how class inheritance was transpiled | |
class CA { | |
static staticMethodA() { | |
return 42; | |
} | |
constructor(name = 'default name') { | |
this.name = name; | |
} | |
methodA() { | |
return this.name; | |
} | |
} | |
class CB extends CA { | |
methodB() { | |
return 43; | |
} | |
} | |
*/ | |
(function () { | |
function CA(name = 'default name') { | |
this.name = name; | |
} | |
CA.prototype.methodA = () => { | |
return this.name; | |
}; | |
function CB() {} | |
CB.prototype = CA.prototype; | |
CB.prototype.methodB = () => { | |
return 43; | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment