Datasheet

Chapter 1: Introduction to JavaScript
21
Moving on to the next statement in our block:
document.write(“ < p > Today is: “ + today.toString() + “ < /p > ”);
Earlier in this chapter I spoke a bit about the DOM (Document Object Model). The document referred to
here is, in effect, the page that you see. There happens to be a method on this object called
write() ,
which allows us to append some text to it. This text may or may not contain HTML tags. In my case,
I create a paragraph tag in the text I output, and I also output the value of my variable.
By using the plus + operator, you can easily concatenate multiple strings together. Here, the three strings
are
< p > Today is: whatever is output by today.toString() , and < /p > . The JavaScript engine
evaluates this operation before passing it on to
document.write and outputting it to the page.
That s all there is to this particular program. After the engine encounters the closing
< /script > tag, it
passes any result on to the layout engine and carries on rendering the remainder of the page.
Summary
By now, you know a lot about how JavaScript got to the place it is today and what you can achieve with
it. You have learned that:
JavaScript evolved gradually from a fairly primitive Netscape scripting extension to a
sophisticated tool supported across the industry. The language continues to progress and
change, and the shape it will take in the future is not entirely certain.
ECMAScript, the standard that JavaScript is based on, has been implemented outside of the
browser in many different technologies, including Microsoft s .NET, Adobe Flex and Flash, and
even on the desktop.
Along with HTML, CSS, and others, JavaScript is just one piece in a sophisticated stack of
technologies that work together. The differences in these technologies among browsers make
JavaScript development challenging at times.
No compiler is required to develop applications. Scripts are developed in a text editor and tested
directly in the browser, making development more accessible.
You were introduced to a basic stack of tools required to do development, including an IDE or
text editor, a web server (needed for Ajax development in particular), and a browser test
environment.
Script blocks containing JavaScript code are executed generally in the order they appear in a
web page.
You were exposed to a basic Hello World type application that made use of script blocks,
variables, and the document object.
In Chapter 2, I ll dig into how the JavaScript language fits into the browser context. I ll get more into the
concept of the Document Object Model, explain the
< script > tag, and talk about how and when
JavaScript gets executed in a web page.
CH001.indd 21CH001.indd 21 6/25/09 7:53:24 PM6/25/09 7:53:24 PM