Expand to array using spread

const originalArray = [1, 2, 3]; const clonedArray = […originalArray]; console.log(clonedArray); // Output: [1, 2, 3]

Merge array using rest

const array1 = [1, 2, 3]; const array2 = [4, 5, 6]; const array3 = [7, 8, 9]; const mergedArray = […array1, …array2, …array3]; console.log(mergedArray); // Output: [1, 2, 3, 4, 5, 6, 7, 8, 9]

Simplify function arguments with rest

function concatenateStrings(separator, …strings) { return strings.join(separator); } console.log(concatenateStrings(" ", "Hello", "world!")); // Output: "Hello world!"

Rest operator detail example

const numbers = [1, 2, 3, 4, 5]; const [first, …rest] = numbers; console.log(first); // Output: 1 console.log(rest); // Output: [2, 3, 4, 5]

Spread operator example

const array1 = [1, 2, 3]; const array2 = [4, 5, 6]; const mergedArray = […array1, …array2]; console.log(mergedArray); // Output: [1, 2, 3, 4, 5, 6]

Rest operator example

function sum(…numbers) { return numbers.reduce((total, num) => total + num, 0); } console.log(sum(1, 2, 3, 4, 5)); // Output: 15

Form element with fetch request

Initialise Firebase Admin and Google Cloud Storage in NodeJS project

const { initializeApp, cert } = require(‘firebase-admin/app’); const { getStorage } = require(‘firebase-admin/storage’); const serviceAccount = require(‘./path/to/serviceAccountKey.json’); initializeApp({ credential: cert(serviceAccount), storageBucket: ‘<BUCKET_NAME>.appspot.com’ }); const bucket = getStorage().bucket();

visibilitychange event

document.onvisibilitychange = function() { if (document.visibilityState === ‘hidden’) { navigator.sendBeacon(‘/log’, analyticsData); } };

pagehide event

const pageHideListener = (event) => { //Send something to back end fetch(‘uri’) }; window.addEventListener("pagehide", pageHideListener);