Created
June 20, 2016 17:15
-
-
Save ymyzk/b0e065956978faed5116c4cacbb8efe5 to your computer and use it in GitHub Desktop.
Simple example of proper tail calls in ECMAScript 2015
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Example of Proper Tail Calls</title> | |
</head> | |
<body> | |
<h1>Example of Proper Tail Calls</h1> | |
<p> | |
Please open console. If your web browser supports proper tail calls, it shows "It works!". | |
</p> | |
<script> | |
"use strict"; | |
function f(n){ | |
if (n <= 0) { | |
return "It works!"; | |
} | |
return f(n - 1); | |
} | |
console.log(f(1000000)); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment