Adding code to head to all pages manually

You might use the wp_head action,
That is triggered within the section of the user’s template by the wp_head() function.

add_action("wp_head", "hook_js");

function hook_js() {
if(is_home() || is_front_page(){
    $output="<script> alert('Page is loading...'); </script>";

    echo $output;
    }
 }

Note that is better to add style and script with the action wp_enqueue_scripts and then enqueue and register them with their proper functions (wp_register_script & wp_enqueue_script)