Microflows are run on the server so you can’t use JavaScript, however Nanoflows are run on the client.
You could look at using a JavaScript action to return a value to a Nanoflow. If you still needed to use a Microflow, you could call it from the Nanoflow.
https://docs.mendix.com/howto/extensibility/write-javascript-actions
Hope this helps