I am trying to learn WP theme development. And at the moment I am trying to figure out how to use data from the loop in JavaScript.
Lets say I got some JavaScripts functions in a external script-file loaded with wp_enqueue. And that this script needs to usa alot of data from the meta for posts.
What is best practice to get this data from the loop to my script. Should I loop the data out to global JavaScript Arrays or Object that my script then use? What is "best practice"? I am especially thinking about "to keep JavaScript code away from the templates, and should only be loaded from external files".
I have also read somewhere that when you use global variables, arrays or object in WP you need to comment this in the top of the file? Is this correct? And what exactly should I write in this comment head?