Hello, World! in ECMAScript

Example for versions SpiderMonkey (Firefox 3.5)

JavaScript uses different commands to output messages depending on what environment is it used in:

  • print: for interpreters with command-line interface prints the message to standard output stream, but when used in web-browser, calls print dialog instead;
  • document.write: when used in web-browser, prints the message to the current document (web-page);
  • console.log: a command for Firebug plugin which prints the message to debug console of the plugin;
  • alert: when used in web-browser, creates a pop-up information window with the message.
print('Hello, World!');

document.write('Hello, World!');

console.log('Hello, World!');

alert('Hello, World!');