This example shows how you can define the function to take a parameter, and then call it with the Twig variable as an argument. Note that the call to handleSubMenuExpansion with the Twig variable as argument is made within a <script> block in the Twig file to ensure that Twig correctly replaces the variable reference with its actual value before sending the page to the browser.
To keep your original structure and integrate the Twig variable directly within a function that takes a parameter, we can adjust the code to receive currentArticleArticleGroup as a parameter. This means that you need to call this function with the Twig variable as an argument somewhere in your Twig template.
Note that since the JavaScript code now depends on a dynamic Twig variable, this part of the code must be executed inside the Twig template for Twig to process and insert the variable value correctly. Here is an updated version of the function with your original name and structure: