How to get, in WP page’s script, a wp enqueued script (in Functions.php)?

You have to make sure your script is registered with wp_register_script before your call to wp_localize_script.

So in your functions.php file:

add_action('init',’my demo_function');
function my demo_function() {


    // Register the script
    wp_register_script( 'myuserscript', 'path/to/myscript.js' );

    // Localize the script with your data
    $theid=get_current_user_id();
    $params = array(
        'userid' => $theid
    );
    wp_localize_script( 'myuserscript', 'MyUserParams', $params );

    // Enqueued script with localized data.
    wp_enqueue_script('myuserscript');
}

Then the parameter would be available to you in the frontend

<script>
    var myData = MyUserParams.userid; 
    alert("your id is: " + myData)
</script>

Reference: wp_localize_script