func main() {
let ans = fact(5);
println(ans);
}
func fact(num) {
if num < 1 {
return 1;
}
return fact(num-1) * num;
}
- func: declare a function
- let: declare a immutable variable
- var: declare a mutable variable
- return: return value of function
- if: if statement
- for: for loop
- println: convert to console.log in js directly
- The entry of this language is main function
- Every expression should be end with a semicolon