Last active
September 6, 2021 02:04
-
-
Save JimYaaa/d96f4eaa9ba23ae1e020eba5cfa45072 to your computer and use it in GitHub Desktop.
Recursive Function
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 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