Output javascript inside twig variable
Since Twig is server-side, and Javascript (usually) is client-side, you would need to change your code's logic so that the desired value you need inside that Twig command can be injected using javascript on the client's side.
Then you could send that data back along with the rest of the submission.
If you need server-side javascript, you would want to look at node.js