You'd typically use the {% includeJs %}
or {% includeJsFile %}
tags within your page template, to specify your page-specific JavaScript, and then output everything in your layout template by calling {{ getFootHtml() }}
.
Here's how your (very basic) page template might look in practice:
{# mypage.twig #}
{% extends '_layout' %}
{% includeJsFile "/assets/js/mypage.js" %}
And here's how your (equally basic) layout template might look:
{# _layout.twig #}
<!doctype html>
<html>
<head></head>
<body>
{# This outputs the JavaScript from mypage.twig #}
{{ getFootHtml() }}
</body>
</html>