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

Not sure why (sometimes there a legit reasons but rare), but maybe if you shared the file contents, we might be able to suggest a way of putting it in a single script tag or like @ArielLeslie suggested, a single external JS file that is linked to the page .

1 Like

Again, if you share the contents of each JavaScript file and your html file, we can possibly guide you to a solution. If not, then we can not help you.