Enqueueing scripts selectively & activation where needed

If you’re only enqueueing scripts when they’re needed, you can check in JS if the plugin’s namespace exists before trying to use it:

if( $.fn.slider ) {
    $('#slider').slider();
}

or another option is to pass some script vars via wp_localize_script:

$wpa_script_data = array(
    'is_front_page' => is_front_page(),
    'slider_options' => array(
        'speed' => 6000
    )
);

wp_localize_script(
    'main-js',
    'wpa_vars',
    $wpa_script_data
);

then in js:

if( wpa_vars.is_front_page ) {
    $('#slider').slider({
        'speed' : wpa_vars.slider_options.speed
    });
}