Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
175
rated 0 times [  182] [ 7]  / answers: 1 / hits: 58218  / 10 Years ago, thu, october 30, 2014, 12:00:00

I have created one javascript file in which I have declared different string constants.



now in another javascript file I want to use those String constants from already created javascript file.



Is there any way to do this.



Thanks in advance.


More From » javascript

 Answers
76

If you declare your constants in file1 as global variables:



var someConstant = 42;


Then you can just use that variable in your other JS files. Just make sure file1 is loaded before you try to use them.



However, polluting the global scope like this come with it's risks, as those variables are easily changed.


[#68964] Tuesday, October 28, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dayshadelaniej

Total Points: 668
Total Questions: 121
Total Answers: 121

Location: Sao Tome and Principe
Member since Wed, Dec 21, 2022
1 Year ago
;