Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
const [first, second, third] = [10, 20, 30]; console.log(first, second, third); // 10 20 30 const [, , x] = [1, 2, 3]; console.log(x); // 3 const [a = 5, b = 7] = [1]; console.log(a, b); // 1 7 let p = 1, q = 2; [p, q] = [q, p]; console.log(p, q); // 2 1 const [head, ...tail] = [1, 2, 3, 4]; console.log(head); // 1 console.log(tail); // [2,3,4] function minMax(arr) { return [Math.min(...arr), Math.max(...arr)]; } const [min, max] = minMax([3, 1, 4, 1, 5]); console.log(min, max); // 1 5
Result
Open