Passing variables from a script tag to another

I have write a script with script tag within head and some other script in another script tag within body tag. I have defined a variable as a global variable in a script tag which has placed inside the head. and I need to update the value of that global variable in both script tag. is it possible or not? it shows some error on this

Why are you using multiple script tags?

Initially I have write all of my script within body tag. then only I realize that, some script needs to be written within head tag. So I wrote that particular script within head tag

Generally, I would suggest creating a separate JavaScript file that you link to the page. If you want to use embedded script tags, I suggest using only one.

1 Like