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
Очередь синхронного кода (callstack) | |
Очередь микрозадач (Promise) | |
Отдельная очередь браузера для отрисовки содержимого (requestAnimationFrame) | |
Очередь макрозадач (setTimeout() и setInterval() или AJAX-запросы) | |
requestAnimationFrame(() => console.log('1 animation frame')); | |
setTimeout(() => console.log('2 timeout'), 0); | |
Promise.resolve().then(() => console.log('3 promise')); | |
console.log('4 sync'); |
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
const url = 'http://lol'; | |
function apiGet(url, attempts = 5) { | |
return new Promise(function core(resolve, reject) { | |
fetch(url) | |
.then((res) => { | |
resolve(res) | |
}) | |
.catch(() => { | |
if (attempts) { |
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
new Promise((resolve, reject) => { | |
throw new Error('err'); | |
}) | |
.then(() => { | |
console.log('then'); | |
}) | |
.catch(() => { | |
console.log('catch'); | |
}) | |
.catch(() => { |
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
'use strict' | |
x = 5; // error! next examples with let x | |
console.log(++x); // 6 | |
console.log(x++); // 6 | |
function foo() { | |
console.log(x); // undefined, because there is x below | |
x += 5; |
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
const array1 = [{ | |
"id": 1, | |
"name": "apple", | |
}, { | |
"id": 2, | |
"name": "orange" | |
}]; | |
const array2 = [{ | |
"id": 1, |
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
// Расшифруйте эту строку. Строка содержит пробел и буквы латинского алфавита. | |
let input = '711141019711632119111114107'; // Great work | |
let result = ''; | |
function findFirstChar(n) { | |
let char = String.fromCharCode(n); | |
if (/[a-z|A-Z ']/.test(char)) | |
return char; | |
else |