javascript return multiple values from a function
//function that returns multiple values function getTopTwoColors() { return ["blue", "pink"]; } var topTwoColors=getTopTwoColors(); var firstValue=topTwoColors[0]; //get first return value var secondValue=topTwoColors[1]; //get second return value
Here is what the above code is Doing:
1. We create a function called getTopTwoColors that returns an array of strings.
2. We call the function and store the return value in a variable called topTwoColors.
3. We access the first value in the array and store it in a variable called firstValue.
4. We access the second value in the array and store it in a variable called secondValue.