main is the name of a function, a function can be thought of as a collection of statements that are clubbed together under a name using which we can reference these statements and execute them. A function may take an input and produces an output.
In JS the code is read from top to bottom and executed, so in the code snippet you shared the author has defined a method called main. The definition of a function starts with the keyword function followed by the function name and an argument list which is enclosed in () and separated by a comma. So your code is executed in a top bottom fashion like below
var g = {}; //Creates an object
main(); //Main method is called, i.e. the statements defined in the main function are executed
g = null; //the object is set to null
//This is the definition of the main function,
function main(){
blnResult = createDialog(); //Method names createDialog is called here, and its output value is stored in blnResult
//if(blnResult){addWatermark()};}
Look at the comments i put in your code to explain each statement. main is not a special method you can name it anything you like, just the rule that the code is executed top to bottom should be remembered. Also if you write all the statements of the main method outside then also the code will execute the same like below
var g = {}; //Creates an object
blnResult = createDialog();
//if(blnResult){addWatermark()};
g = null; //the object is set to null
Hope this helps
-Manan