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 months = ['March', 'Jan', 'Feb', 'Dec']; | |
| months.sort(); | |
| console.log(months); | |
| // expected output: Array ["Dec", "Feb", "Jan", "March"] |
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 array = ['bingöl', 'ordu', 'adana']; | |
| let sortedArray = array.slice().sort(); | |
| console.log(array); // (3) ["bingöl", "ordu", "adana"] |
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 numbers = [4, 2, 5, 1, 3]; | |
| numbers.sort((a, b) => a - b); | |
| console.log(numbers); // [1, 2, 3, 4, 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
| var x = 10; console.log(x); |
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 promise = new Promise(function(resolve, reject) { | |
| // Executor function | |
| }); |
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 promise = new Promise(function(resolve, reject) { | |
| setTimeout(() => resolve("done"), 1000); | |
| }); |
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 promise = new Promise(function(resolve, reject) { | |
| setTimeout(() => reject(new Error("Whoops!")), 1000); | |
| }); |
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 promise = new Promise(function(resolve, reject){ | |
| resolve("done"); | |
| reject(new Error("…")); // ignored | |
| setTimeout(() => resolve("…")); // ignored | |
| }); |
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 promise = new Promise(function (resolve, reject) { | |
| resolve('basarili!'); | |
| reject(new Error('hata alindi!')) | |
| }) | |
| promise.then( | |
| function (result) { | |
| console.log(result); | |
| }, | |
| function (error) { | |
| console.log(error); |
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
| promise.then( | |
| result => alert(result), | |
| error => alert(error) | |
| ); |
OlderNewer