Small First Program

This is a small version of programs I write every day. This is sometimes called a "Hello World" program because it shows how to write and run a program that does little more than say hello.

The simplest way to run a program is to use html with a script tag. Create a file pi.html containing these lines:

<p id=result> <script> result.innerText = Math.PI </script>

View results with the browser's Open File ... menu option.

# Variations

Often the <p> tag is closed with a </p> tag though this is less necessary than closing script tags.

Often the id value is written id="result" though the quote marks are optional when value has no special characters.

Often hints like style="font-size: x-large;" will display text in extra large letters.

Often the script tag specifies the type of script. Type module is preferred for ES6 javascript. Within modules one writes window.result to access elements of the window.

Often the entire html is enclosed in an <html></html>. When this is omitted it is assumed.

Often files start with the html comment <!DOCTYPE html> which removes some ambiguity.

MDN Search Terms p, script, pi, innertext, assignment, property accessors, style, es6, module, doctype