Is it possible to define a global variable in a JavaScript function? I want use the trailimage variable (declared in the makeObj function) in other functions. Answer As the others have said, you can use var at global scope (outside of all functions and modules) to declare a global variable: (Note that that’s only true at global scope. If that
Tag: declaration
Declaring multiple variables in JavaScript
In JavaScript, it is possible to declare multiple variables like this: …or like this: Is one method better/faster than the other? Answer The first way is easier to maintain. Each declaration is a single statement on a single line, so you can easily add, remove, and reorder the declarations. With the second way, it is annoying to remove the first