How to properly add inline Javascript?
If you want inline javascript in order to pass some computed variables, then it seems that the only way to do it in D8 is to use a combination of drupalSettings and an attached library.  The following snippets are copied from Attaching configurable JavaScript in the official docs.
In mymodule.libraries.yml, declare a library containing your javascript file, with a dependency on drupalSettings (and on jQuery):
cuddly-slider:
  version: 1.x
  js:
    js/cuddly-slider.js: {}
  dependencies:
    - core/jquery
    - core/drupalSettings

Then, when building (or altering) your render array, attach the library and save something to the settings:
$build['#attached']['library'][] = 'fluffiness/cuddly-slider';
$build['#attached']['drupalSettings']['fluffiness']['cuddlySlider']['foo'] = 'bar';

Presumably, you have something more interesting than 'bar'.  Finally, access the setting in your javascript file as drupalSettings.fluffiness.cuddlySlider.foo.