main() function (Definition)

The main entry point to a procedural language program.

Property/method value type:Implementation defined

Although JavaScript in many circumstances does not have a main() function, in some applications of the language it may be necessary.

By implication, the main() function of a JavaScript is the global code that is present in a web page in the <SCRIPT> tags but, is not part of a function declaration body.

When embedded in a browser, the language is invoked according to an event model and the browser itself is the main() for the interpreter. Various script based functions are called by the browser.

In a server side environment, a script may be used as the result of a CGI call. In that case, a main() with passed parameters is a more useful facility.

In some implementations, the main() function may be used to make the language accessible to C programmers. Languages often borrow from one another and JavaScript borrows heavily from C language and Java. The exact form of the main() function and possibly its name will be implementation dependant and you should check the documentation for the interpreter just make sure it behaves the way you expect.

The result of calling the main() function will be implementation specific, but probably an integer.

See also:argc parameter, argv parameter, Execution context, Execution environment, Host environment, Host object