Syntax - what does square brackets around a variable declaration mean [duplicate] Syntax - what does square brackets around a variable declaration mean [duplicate] arrays arrays

Syntax - what does square brackets around a variable declaration mean [duplicate]


It's called Destructuring assignment, and it's used to unpack the values of an array and assign them to new variables.

So here in your code:

const [component] = router.getMatchedComponents({ ...to })

You are assigning to the component variable the first element held in the array that will be returned by router.getMatchedComponents({...to}), where to is an array-like structure turned into object using the spread operation.