Just perusing JSE tonight and thought there'sThere are a few other ways to outline for what you're asking about.
SEO Considerations
If you run Google Lighthouse on your site to measure the performance, you may find that there may be performance and best practice recommendations to delay loading of render-blocking javascript. As a result, loading your custom JS in the head may cause a performance issue, so loading it later is recommended.
Loading it in the article
As @pe7er notes, by default you can not directly add PHP code, and sometimes JS code into the article, depending on your site's editor'seditor configuration.
For example, if using JCE as your editor, you can modify the editor profile to allow PHP and JS code to be included. That's not recommended though as it can create security issues, or potentially white screen errors if your syntax is wrong.
There are some 3rd party extensions I use that can assist with inserting code, such as Regular Labs Sourcerer, where you can then use a shortcode to wrap around PHP code which is then deactivated in the editor, but will render the code in the page.
Loading it in the footer or debug position
Rather than needing to repeatedly remember to add the code in the article, the third place I would look to load the code is via a module in either a footer module position, or the debug position.
The debug position would load it just before the closing body and html tags. This would delay the loading for performance purposes.
I'd also look at assigning that module to either the category that you need the JS to load for (if it's common to all articles in a category), assign it to specific pages or articles, or assign it based on other rules. You might need Regular Labs Advanced Module Manager in order to extend your options on how to assign the module to particular subsets of content.