Last active
September 7, 2021 10:38
-
-
Save AnsonH/090c4b73577bfabb88365adce181464e to your computer and use it in GitHub Desktop.
Javascript Tip #1 - Directly invoke arrow functions
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
/* Tweet: https://twitter.com/AnsonH_/status/1435189821740175363?s=20 */ | |
/* Example 1 */ | |
(() => { | |
console.log("Hello!"); | |
})(); | |
// Equivalent to... | |
(function() { | |
console.log("Hello!"); | |
})(); | |
/* Example 2 */ | |
(async () => { | |
const response = await fetch("https://jsonplaceholder.typicode.com/todos/1"); | |
const data = await response.json() | |
console.log(data); | |
})(); | |
// Instead of... | |
fetch('https://jsonplaceholder.typicode.com/todos/1') | |
.then(response => response.json()) | |
.then(json => console.log(json)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment