Skip to content

Instantly share code, notes, and snippets.

@ymyzk
Created June 20, 2016 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ymyzk/b0e065956978faed5116c4cacbb8efe5 to your computer and use it in GitHub Desktop.
Save ymyzk/b0e065956978faed5116c4cacbb8efe5 to your computer and use it in GitHub Desktop.
Simple example of proper tail calls in ECMAScript 2015
<!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