✅ – Script – 13-00 Dec 1

is this a correct syntax const [response] = await tasks.createTask() Im familiar with the object destructuring method but this looks kinda weird
S
S3BAS504d ago
yeah it's valid syntax
UU
Unknown User504d ago
S
Script504d ago
oh but how does it work tho I tried testing it by creating a function to return an array ["response", "jason"] then I did const ["jason"] = function();` then console logged it and it kept on returning "response"
S
S3BAS504d ago
The word that goes in the [] is the assigned variable name And it's based on the position
const [horse, tiger] = ["response", "jason"]
console.log(horse) // response
console.log(tiger) // jason
const [horse, tiger] = ["response", "jason"]
console.log(horse) // response
console.log(tiger) // jason
horse and tiger can be whatever you want, it's the name of the variable you are declaring
S
Script504d ago
oh same way with useState so it doesnt matter what i name the first and second index, the first would always be the state variable then the second would always be what changes the state variable
S
S3BAS504d ago
Yeah, because useState returns an array, the first element holding the current value and the second giving you the function that can update it
UU
Unknown User504d ago
S
S3BAS504d ago
Which you are destructing
S
Script504d ago
that makes sense thanks
UU
Unknown User504d ago