Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use a variable of one <script> in another <script> in javascript?

How can I use a variable of one in another in javascript?

like image 362
jaffar Avatar asked Jul 08 '09 06:07

jaffar


People also ask

How do I pass a variable from one script to another in JavaScript?

There are two ways to pass variables between web pages. The first method is to use sessionStorage, or localStorage. The second method is to use a query string with the URL.

Can you get a variable from one script to another?

In JavaScript, variables can be accessed from another file using the <script> tags or the import or export statement. The script tag is mainly used when we want to access variable of a JavaScript file in an HTML file.

How is a variable accessed from another file?

The variable number is declared globally and may be accessed from other file when including its declaration with the “ extern ” prefix. However, the variable coefficient is only accessible from the file in which it is declared and only from that point on (it is not visible in function main .


1 Answers

If the two script tags are on the same page, any variable declared outside of the scope of a function is global to the page.

like image 194
slolife Avatar answered Sep 22 '22 10:09

slolife