Programming Fundamentals/Introduction/JavaScript

From Wikiversity
Jump to navigation Jump to search

hello.js[edit | edit source]

// This script displays "Hello world!"
//
// References:
//   http://javascript.info/hello-world
//   https://www.w3schools.com/js/js_output.asp
//   http://progopedia.com/example/hello-world/114/

output("Hello world!")

function output(text) {
  if (typeof document === 'object') {
    document.write(text);
  } 
  else if (typeof console === 'object') {
    console.log(text);
  } 
  else {
    print(text);
  }
}

Try It[edit | edit source]

Copy and paste the code above into one of the following free online development environments or use your own JavaScript compiler / interpreter / IDE.

See Also[edit | edit source]