How to invoke JavaScript code with jQuery when scripts were included at the end of html page

How to invoke JavaScript code with jQuery when scripts included at the end (before BODY tag ends)
When your website consists of master layout and multiple views and partials you often need include straightway javascipt blocks with jQuery stuff like domReady(...). Yes, you are programmer-in-trend and you prefer reactjs or angular x.x and don't jQuery but in React's componentDidMount functions it is usefull run jQuery style code to manipulate DOM, so jQuery can live with React too.
But your webapp will fail with something like jQuery or $ is undefined. How to solve the problem when jQuery included after it was called first? No problem.
Follow me. You need define global scrope array of functions, define special function like o_$ and after jQuery is included - iterate over the array and run each function. So well, when you call jQuery code in your partials you cannot use jQuery - instead, you need to wrap your code inside continuation with the function like o_$(function() {  jQuery.domReady(...) }). That is small overhead and looks like workaround but too small disadvantage.
Put code like below:
First, in your html head
    <!--STYLES END-->
<script type="text/javascript">
var _jqueryBeforeArr = [];
function o_$(fn) { _jqueryBeforeArr.push(fn); };
Second, in your views and partials
o_$(function($) {
$(".js-btn-choose-week").click(function() {
let week = $(this).data("week");
location.href = "/endpoint/day?week=" + encodeURIComponent(week);
Third, after jQuery was included
<script src="" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script type="text/javascript">
$.each(_jqueryBeforeArr, function(i, fn) {
    <!--SCRIPTS END-->
That is no more tweaks.
Yes, may be you are a talent programmer or in your project requirements/organization you have to use another best practice like attach scripts with name like view name at the end of html (after jQuery is included) and keep all js code in that separated file. But if you are programmer like me or have to develop projects mostly consist of code-like-shit - use my solution because it is simple and keep your brains fresh.

jquery, javascript, js, html, jquery before