Rest elements in tuples
📖 Scenario: You are organizing a small party and want to keep track of the guests arriving. Each guest's information includes their name, age, and any number of favorite snacks they bring along.
🎯 Goal: Create a tuple to store guest information with rest elements to hold multiple favorite snacks. Then extract and display the guest's name, age, and their favorite snacks.
📋 What You'll Learn
Create a tuple called
guest with the first element as a string for the name, the second element as a number for the age, and the rest elements as strings for favorite snacks.Create a variable called
name to hold the guest's name.Create a variable called
age to hold the guest's age.Create a variable called
snacks to hold the rest of the favorite snacks.Print the guest's name, age, and favorite snacks.
💡 Why This Matters
🌍 Real World
Tuples with rest elements help store fixed and variable data together, like user info plus multiple preferences or items.
💼 Career
Understanding tuple rest elements is useful for TypeScript developers working with complex data structures in web apps or APIs.
Progress0 / 4 steps