Promises

Run Settings
LanguageJavaScript
Language Version
Run Command
let newArr = [10, 100]; const first = new Promise((resolve, reject) => { setTimeout(resolve, 6000, 'Все ок!'); }); const second = new Promise((resolve, reject) => { setTimeout(reject, 2000, new Error('Неудачно')); }); Promise.race([first, second]).then((result) => { console.log(result); }); const third = new Promise((resolve, reject) => { setTimeout(resolve(1000), 2000); }); function save(list){ return third.then(result => { list.push(result); }); } save(newArr) .then(() => console.log(newArr)) .catch(err => console.log(err));
const f1 = fetch('https://jsonplaceholder.typicode.com/todos/1'); const f2 = fetch('https://jsonplaceholder.typicode.com/todos/2'); Promise.all([f1, f2]).then((res) => { console.log('Array of results', res); }) .catch((err) => { console.error(err); });
Editor Settings
Theme
Key bindings
Full width
Lines