JavaScript · Junior · Question 61 of 75
What does [a, b] = [b, a] do?
- ✓Correct answer: Swaps the values of
aandbwithout a temporary variable - 2Creates a nested array
- 3Throws a syntax error
Explanation
The right side creates a temporary array, then destructuring assigns its elements. If the previous line has no semicolon, it may be parsed as an index access - another reason to use semicolons or a linter.