// This file is generated by ChatGPT const { log } = console // Define a class using ES6 class syntax class Person { /** * Creates an instance of Person. * * @param {string} name Name * @param {number} age Age */ constructor(name, age) { this.name = name this.age = age } // Define a method within the class sayHello() { log(`Hello, my name is ${this.name} and I am ${this.age} years old.`) } } // Create an array of objects const people = [new Person('Alice', 30), new Person('Bob', 25), new Person('Charlie', 35)] // Use the forEach method to iterate over the array for (const person of people) { person.sayHello() } // Use a template literal to create a multiline string const multilineString = ` This is a multiline string that spans multiple lines. ` // Use destructuring assignment to extract values from an object const [firstPerson] = people if (firstPerson !== undefined) { const { age, name } = firstPerson log(`First person in the array is ${name} and they are ${age} years old.`, multilineString) } // Use the spread operator to create a new array const numbers = [1, 2, 3] const newNumbers = [...numbers, 4, 5] log(newNumbers) // Use a try-catch block for error handling try { // Attempt to parse an invalid JSON string JSON.parse('invalid JSON') } catch (error) { console.error('Error parsing JSON:', error) } // Use a ternary conditional operator const isEven = (/** @type {number} */ number_) => number_ % 2 === 0 const number = 7 log(`${number} is ${isEven(number) ? 'even' : 'odd'}.`) // Use a callback function with setTimeout for asynchronous code setTimeout(() => { log('This code runs after a delay of 2 seconds.') }, 2000) export {}