Run JS function when JQ enqueued

You can’t do that way

first you need to enqueue your script using :

wp_enqueue_script('jquery');
wp_enqueue_script('ns-likes-dislikes-for-posts-js', plugin_dir_url(__FILE__). 'path/to/your/js/file/from/plugin/directory/custom.js', array('jquery'), '1.0', true);

in custom js start writing your js with jquery but you can’t use $, instead use jQuery.

if you want to use $ instead of jQuery try this code:

(function($){
  // enjoy jquery with $('selector')
})(jQuery)

first you need to enqueue script then you can localize it.

wp_enqueue_script( 'search-ajax', get_template_directory_uri() . '/js/search-ajax.js', array('jquery'), null, true );
wp_localize_script( 'search-ajax', 'search_ajax_object',
    array( 
        'url' => admin_url( 'admin-ajax.php' ),
    )
);