Skip to content

Instantly share code, notes, and snippets.

@AnsonH
Last active September 7, 2021 10:38
Show Gist options
  • Save AnsonH/090c4b73577bfabb88365adce181464e to your computer and use it in GitHub Desktop.
Save AnsonH/090c4b73577bfabb88365adce181464e to your computer and use it in GitHub Desktop.
Javascript Tip #1 - Directly invoke arrow functions
/* 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