How do I add the JavaScript src file inside a block? I have called the JavaScript source code, &lt;script scr=""&gt;&lt;/script&gt;, inside a block. And this code is working fine.

But I am not sure whether it's good practice or not.

If it's not a good practice, give me some suggestions for adding above code inside the block.
You should add javascript as a library, then attach it to your block in the build array or a preprocess function like this:

$block['#attached']['library'][] = 'mymodule/mymodule.search_filters';
$block['#attached']['drupalSettings']['mymodule'] = [
  'cats' =&gt; 'tabby',
  'dogs' =&gt; 'dalmation',
];