Undeclared, uninitialised variables being used in expressions: what to think?
Question: I'm struggling to understand the following code snippet (located in a file
called `program.js`. My issue is that I can't find where
`CODERBOT_PROG_SAVEONRUN` is declared and/or initialized in this file. No
external code or library seems to be being imported.

I'm running into the same issue in many other places in
[this](http://www.coderbot.org/en/index.html) particular
[project](https://github.com/CoderBotOrg/coderbot). Is this a quirky feature
of JavaScript, or is there somewhere else I should be looking?

What should I think if a variable is used but not initialized and declared in
a given JavaScript file?

Where is it coming from if there is no obvious "import" statement?

    
    
    function runProg() {
        var bot = new CoderBot();
        // Generate JavaScript code and run it.
        window.LoopTrap = 1000;  
        Blockly.Python.INFINITE_LOOP_TRAP = '  get_prog_eng().check_end()\n';
        var code = Blockly.Python.workspaceToCode();
    
        if(CODERBOT_PROG_SAVEONRUN) {
            Blockly.Python.INFINITE_LOOP_TRAP = null;
            var xml_code = Blockly.Xml.workspaceToDom(Blockly.mainWorkspace);
            var dom_code = Blockly.Xml.domToText(xml_code);
            var data =  {'name': prog.name, 'dom_code': dom_code, 'code': code};
            try {
                $.ajax({url: '/program/save', data: data, type: "POST", success:function(){
                    loadProgList();
                }});
            }catch (e) {
                alert(e);
            }
        }
        try {
            var data =  {'name': prog.name, 'code': code};
            $.ajax({url: '/program/exec', data: data, type: "POST"});
            $("#dialogRunning").popup("open", {transition: "pop"});
            setTimeout(statusProg, 1000);
        } catch (e) {
            alert(e);
        }
    }
    


Answer: In JavaScript, there is a global context, and local contexts defined by
functions. If a variable is not defined inside a function, it is defined on a
global context. In a browser, the global context is `window`; all scripts you
run in that window share the same global context.

The variable you are looking for is defined in `templates/config_params.html`.
Both it, and the `program.js` script are included from `templates/main.html`,
which makes global variables of each visible to the other when displaying that
page.

