Question:
Javascript variable values are given in an external .js file,?
diana
2007-10-05 06:26:47 UTC
but the functions are defined in the html file that calls that external file. The function' parameters use the variable values in the external file, are my functions going to work?
By calling the external file first (in the head tag), the browser should load the variable values in the external .js file first, and then if I place the function definitions after that, all should be fine, right?
Three answers:
anonymous
2007-10-05 06:38:44 UTC
if the variables are global(outside of functions), it should work.

if they are local functions(inside the function()), they need to be nested in the function.

It's best to keep all of the script together, either on the webpage, or externally in the .js file.
saucier
2016-10-21 07:02:16 UTC
you are able to desire to appreciate the variable in the exterior JS document that holds the history colour. That variable needs to have worldwide scope. Assuming you acceptable discover the variable with worldwide scope that holds the cost, then you definately can in basic terms reassign its fee inb your JavaScript. then you definitely would desire to ensure no different applications or statements in the exterior JS document reassign the cost to the history colour variable.
anonymous
2007-10-05 06:31:10 UTC
http://javascript.internet.com/

I think that is how it works. Try it out and see what happens.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Continue reading on narkive:
Loading...