Fix rest parameter mis-match
I think you intended to have working code 😄
This commit is contained in:
parent
a22c2a3d29
commit
b8d1e690f0
1 changed files with 5 additions and 4 deletions
|
@ -53,10 +53,11 @@ Here the first two arguments go into variables and the rest goes to `titles` arr
|
||||||
function showName(firstName, lastName, ...titles) {
|
function showName(firstName, lastName, ...titles) {
|
||||||
alert( firstName + ' ' + lastName ); // Julius Caesar
|
alert( firstName + ' ' + lastName ); // Julius Caesar
|
||||||
|
|
||||||
// the rest = ["Consul", "Imperator"]
|
// the rest go into titles array
|
||||||
alert( rest[0] ); // Consul
|
// i.e. titles = ["Consul", "Imperator"]
|
||||||
alert( rest[1] ); // Imperator
|
alert( titles[0] ); // Consul
|
||||||
alert( rest.length ); // 2
|
alert( titles[1] ); // Imperator
|
||||||
|
alert( titles.length ); // 2
|
||||||
}
|
}
|
||||||
|
|
||||||
showName("Julius", "Caesar", "Consul", "Imperator");
|
showName("Julius", "Caesar", "Consul", "Imperator");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue