HTML and CSS Reference
In-Depth Information
The src attribute is used when the JavaScript code is in an external file, the file name
ending with a .js extension. The src attribute is assigned the name of the file, which can
be prefixed with its location (e.g., a directory tree or URL).
<script type="text/javascript"
src="sample.js">
</script>
<script type="text/javascript"
src="directory/sample.js">
</script>
<script type="text/javascript"
src=" http://hostname/sample.js">
</script>
2.3 Generating HTML and Printing Output
When you create a program in any language, the first thing you want to see is the output
of the program displayed on a screen. In the case of JavaScript, you'll see your output in
the browser window. Of course, browsers use HTML to format output. Although Java-
Script doesn't understand HTML per se, it can generate HTML output with its built-in
methods, write() and writeln() .
2.3.1 Strings and String Concatenation
A string is a character or set of characters enclosed in matching quotes. Because the meth-
ods used to display text take strings as their arguments, this is a good time to talk a little
about strings. See Chapter 9, “JavaScript Core Objects,” for a more complete discussion.
All strings must be placed within a matched set of either single or double quotes; for exam-
ple:
"this is a string" or 'this is a string'
Double quotes can hide single quotes; for example:
"I don't care"
And single quotes can hide double quotes; for example:
'He cried, "Ahoy!"'
Either way, the entire string is enclosed in a set of matching quotes.
Concatenation is caused when two strings are joined together. The plus (+) sign is
used to concatenate strings; for example:
 
 
 
Search WWH ::




Custom Search