How can javascript be added to a custom-page.php template?

Save your JS in a seperate file and use a Conditional to Enqueue it. Something like this will work.

function my_enqueue_stuff() {
    if (is_page_template('custom-page.php')) {
        wp_enqueue_script(
            'my-functions',
            get_stylesheet_directory_uri() . '/my-functions.js', array('jquery'), filemtime(get_stylesheet_directory() . '/my-functions.js')
        );
    }
}
add_action( 'wp_enqueue_scripts', 'my_enqueue_stuff' );

The above will go in your Child Theme’s functions.php file.