We will start with a JavaScript that simply writes some text to a page. Let s construct a script that writes Learning JavaScript with John T is easy and interesting to a web page. Let s examine our script in detail. We need to first tell the browser that a JavaScript is about to follow. All right, then it stands to reason that the document.write command writes the text to the page.
Document is the object, and write is the method being performed on the object.
The text that is included in quotations within the parentheses is written to the page. Text in a document.write command must always be in parentheses. We also need to tell the browser that the line of JavaScript is ending. We do that by adding a semicolon at the end of the line. Try it out for yourself.