Skip to content

Instantly share code, notes, and snippets.

@JimYaaa
Last active September 6, 2021 02:04
Show Gist options
  • Save JimYaaa/d96f4eaa9ba23ae1e020eba5cfa45072 to your computer and use it in GitHub Desktop.
Save JimYaaa/d96f4eaa9ba23ae1e020eba5cfa45072 to your computer and use it in GitHub Desktop.
Recursive Function
function countDown(fromNumber) {
console.log(fromNumber)
let nextNumber = fromNumber - 1
if (nextNumber > 0) {
countDown(nextNumber) // 呼叫自己
}
}
countDown(5)
// Output
// 5
// 4
// 3
// 2
// 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment