Day 16 of 21 Days of Javascript

As a side quest today I used ChatGPT to practice the syntax for javascript arrow functions. Here's the prompt I gave ChatGPT in study mode:

🤖
Arrow functions in JS. I'd like to learn all the different ways of writing them and firm up my knowledge/understanding of them. Provide a brief tutorial, following by coding exercises that test my skill with arrow functions.

ChatGPT provided a series of coding exercises. Here's a snippet of the basics I covered in a short session:

// Q1(a)
function double(n) {
  return n * 2;
}

// rewritten as arrow function
const doubleArrow = n => n * 2;  // return is implicit

// Q1(b)
function greet(name = "world") {
  return "Hello, " + name + "!";
}

// rewritten as arrow function
const greetArrow = (n = "World") => `Hello ${n}!`


// Q1(c)
function makeUser(id, name) {
  return { id: id, name: name };
}

// rewritten as arrow function
const makeUserArrow = (id, name) => ({ id: id, name: name});

// Q1(d)
function sumAll() {
  return Array.from(arguments).reduce((a, b) => a + b, 0);
}

// rewritten as arrow function
const sumAllArrow = (...nArray) => nArray.reduce((a, b) => a + b, 0);