Last active
January 20, 2018 12:13
-
-
Save kevinchisholm/93a4006ca7bfa5ddb2dd3e9ecec72e91 to your computer and use it in GitHub Desktop.
JavaScript Rest Parameter – Basics
This file contains 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
x -> a | |
arg 0 -> b | |
arg 1 -> c | |
arg 2 -> d | |
arg 3 -> e | |
arg 4 -> f |
This file contains 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
function inspectArgs(x, ...theArgs) { | |
if (x) { | |
console.log('x -> ' + x); | |
} | |
theArgs.forEach((arg, index) => { | |
console.log('arg ' + index + ' -> ' + arg); | |
}) | |
} | |
inspectArgs('a', 'b', 'c', 'd', 'e', 'f'); |
This file contains 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
x -> a | |
arg 0 -> c | |
arg 1 -> d | |
arg 2 -> e | |
arg 3 -> f |
This file contains 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
function inspectArgs(x, y, ...theArgs) { | |
if (x) { | |
console.log('x -> ' + x); | |
} | |
theArgs.forEach((arg, index) => { | |
console.log('arg ' + index + ' -> ' + arg); | |
}) | |
} | |
inspectArgs('a', 'b', 'c', 'd', 'e', 'f'); |
This file contains 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
arg 0 -> a | |
arg 1 -> b | |
arg 2 -> c | |
arg 3 -> d | |
arg 4 -> e | |
arg 5 -> f |
This file contains 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
function inspectArgs(...theArgs) { | |
theArgs.forEach((arg, index) => { | |
console.log('arg ' + index + ' -> ' + arg); | |
}) | |
} | |
inspectArgs('a', 'b', 'c', 'd', 'e', 'f'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment