When you use wp_enqueue_script(), you are enqueueing your file in the header or the footer, depending on the fifth parameter passed in the function.
A clean way to bring variables into a js file depending on your page's query : wp_localize_script() to bring localization or special request available into a js file.
// Register the script
wp_register_script( 'some_handle', 'path/to/myscript.js' );
// Localize the script with new data
$translation_array = array(
'some_string' => __( 'Some string to translate', 'plugin-domain' ),
'a_value' => '10'
);
wp_localize_script( 'some_handle', 'object_name', $translation_array );
// Enqueued script with localized data.
wp_enqueue_script( 'some_handle' );
in the js script, you'll be able to retrieve the variables
<script>
// alerts 'Some string to translate'
alert( object_name.some_string);
</script>
Read more on the codex wp_localize_script
If you want to load different js file depending on the query, you have to add php statement into the function call with wp_enqueue_scripts action (beware of the ending S).