Looks like the best way is using:
add_action('wp_footer', returnJs);
But if my returnJs function is inside my shortcode function and it's used more than once on a page it will return an error trying to re-create the function.
Is there a way to use add_action and have my js code in a variable instead of wrapped in a function or maybe another way to include it.
It is dynamically generated based on a variable in the short code so the js will be unique for each shortcode.
Thanks in advance.