Board Thread:General Coding Help/@comment-9605025-20180428232938/@comment-27345308-20180504161120

Since these are VisualEditor system messages they should cover most languages, I believe. Fallback to wgContentLanguage is already there, if the messages don't exist in user's language they will be displayed in a fallback language, which is (eventually) English.

It's important where it's located because the code is executed asynchronously. Consider the following: There are three errors here: The correct code would look like: Now, that looks (and works) fine, more or less, but what if you had something like You could also extract your asynchronous calls to separate functions, like: This now has less indentation, but the  and   functions will now be exposed to global scope  which is usually a bad idea (unless you really need other scripts to use your functions), so something like this would be a final version of this demonstration: So it all boils down to async and scoping issues. :P
 * 1)   is not defined at the time the code fetching the messages is running and will throw an error unless the code is running really late into page loading because the code is not waiting for the   ResourceModule to load, that is, it's not placed in the callback function that's called right after it gets defined.
 * 2)   and   messages will not be defined because they are in a different function scope from your code.
 * 3) Even the two variables were defined in the same function scope as your code, they will be undefined at the time you're using them, because you're not waiting for the API call to finish (that is, your code isn't placed inside the callback function that fires when the API call finishes)

This all might sound confusing, but people new to JS are very often confused by asynchronous calls, callbacks, order of execution, etc. and it would take some experience to completely understand why things work the way they work.