Created
November 24, 2021 19:10
-
-
Save catwhocode/267630c6b3aba18a5798e18a8e2d8867 to your computer and use it in GitHub Desktop.
Destructuring Rest Parameter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// source: | |
// https://dev.to/sagar/three-dots---in-javascript-26ci | |
function myFunc(...[x, y, z]) { | |
return x * y* z; | |
} | |
myFunc(1) // NaN | |
myFunc(1, 2, 3) // 6 | |
myFunc(1, 2, 3, 4) // 6 (fourth parameter is not destructured) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment