Skip to content

Instantly share code, notes, and snippets.

View decentraliser's full-sized avatar
🦈
In a sharking mood

Decentraliser🌵🍄 decentraliser

🦈
In a sharking mood
View GitHub Profile
@decentraliser
decentraliser / functional-programming.js
Last active June 7, 2023 05:41
Functional programming examples in JavaScript
// COMMON OPERATIONS ON ARRAYS:
// CREATE A NEW VARIABLE
// Array.map => create a new array from an existing array. Each return is a new element of the new array
// Array.filter => create a new array: keeps elements when return true, removes elements when return false
// Array.reduce => create something new (number, string, object, array...) from an existing array. return adds things to the accumulator (acc)
// EXECUTE SIDE EFFECTS
// Array.foreach => Do stuff with each array item (it does not return anything)
@decentraliser
decentraliser / async-javascript-basics.js
Last active June 7, 2023 05:35
Async JavaScript basics: Promises and async/await
// Asynchronous JavaScript basics
// Asynchronous programming is a way to execute code
// without blocking the execution of the rest of the program.
// We commonly use the asynchronous syntax when we need to
// => Get data from another website or API
// => Retrieving / storing data in a database
// => Write / Read files from file system
@decentraliser
decentraliser / jsdocs-type-casting.js
Created January 14, 2022 10:01
jsdocs type casting
const subUser = /** @type {SubUserType} */ (/** @type {unknown} */ (user))