Some create hidden elements in the DOM and access the values in the JS files. But this approach would create an unnecessary element in the DOM.
Now let’s explore the correct and the easiest way to pass values to JS files.
Follow the below steps to pass variable values to JS files.
Step 2. Then initialize that file with the following values as follows;
Below is the code for init function to be written in the js page
Note that the first parameter Y, which is an instance of the YUI object, is automatically passed to our function by the Page Requirements Manager.
The second parameter is the variable in which we are actually receiving the initialization data
You can see that we have assigned the initvariables value to initvalues global variable and now we can use this global variable throughout the js page.
Try printing the initvalues values in console out of the scope of init function