deepkumar patel
deepkumar patel

Reputation: 1

Variable assigned value

const questions = [
    "What is your name ?",
    "Your City : ",
    "Your Country : "
];
const collectAnswers = (questions, done) =>{
    const answers = [];
    const [firstQ] = questions;

here, I want to ask that what will be the value stored in const [firstQ] = questions ? Is it hold every text an array or just the text on first index of an array ?

Upvotes: -1

Views: 30

Answers (1)

jonowles
jonowles

Reputation: 466

This is array destructuring syntax, meaning that it will assign the value of the first item in the questions array to a variable named firstQ.

You can do this with as many array elements as you want. For example:

const [ foo, bar, baz ] = [ 'foo', 'bar', 'baz' ];

This will asign the variables foo, bar, and baz to the corresponding strings from the array on the right.

Upvotes: 1

Related Questions