This file contains 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
// timeouts are handy to fake async calls | |
// setTimeout(callback function, 1500 /*milliseconds*/, 'parameters'); | |
function doSomething(name, callback){ | |
// 2.) task 1: we execute console.log('1'); | |
console.log('1'); | |
// 3.) task 1: we execute setTimeout. Set timeout creates a new task (task 2) that will be executed in 1500 milliseconds from now on | |
setTimeout(callback, 1500, name); | |
// 4.) task 1: we execute console.log('2'); | |
console.log('2'); | |
} |
This file contains 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
// the scope of a let variable is the current block scope | |
// the scope of a var variable is the current function scope (if there is no function, than the scope is global) | |
// using var in this example will execute the loop and compute var i to the value 10 | |
// than the timeout callbacks will callback one after the other and access i which is globally set to 10 | |
for(var i = 0; i < 10; i++){ | |
setTimeout(function () { | |
console.log(i); | |
}, 1500, i); | |
} |
This file contains 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
const myString = "Foo Bar"; | |
const needle = "fOO"; | |
let isCaseInsensitive = myString.includes(needle)); // => isCaseInsensitive is false | |
isCaseInsensitive = myString.toUpperCase().includes(needle.toUpperCase()); // => isCaseInsensitive is true |
NewerOlder