<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Clickfire &#187; JavaScript</title>
	<atom:link href="http://www.clickfire.com/viewpoints/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.clickfire.com</link>
	<description>Web reviews and how to&#039;s for site owners, bloggers and social media users</description>
	<lastBuildDate>Mon, 30 Jan 2012 13:05:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Starting with JavaScript Tutorial</title>
		<link>http://www.clickfire.com/starting-with-javascript-tutorial/</link>
		<comments>http://www.clickfire.com/starting-with-javascript-tutorial/#comments</comments>
		<pubDate>Sat, 24 Nov 2007 20:30:43 +0000</pubDate>
		<dc:creator>Guest Author</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web Dev]]></category>
		<category><![CDATA[beginner tutorials]]></category>
		<category><![CDATA[javascript tutorial]]></category>
		<category><![CDATA[javascript tutorials]]></category>

		<guid isPermaLink="false">http://www.clickfire.com/starting-with-javascript-tutorial/</guid>
		<description><![CDATA[Attention beginning JavaScripters. Here is a chance to dive into this web only scripting language with simple explanations and sampleimages. All you need is a little basic HTML knowledge and an understanding of basic programming logic. Check out Michel Barakat's viewpoint.]]></description>
			<content:encoded><![CDATA[<p>Michel Barakat</p>
<h2>Requirements:</h2>
<ol class="unNumList">
<li>Basic HTML Knowledge</li>
<li>Basic Programming Logic Knowledge</li>
</ol>
<p><span id="more-67"></span></p>
<h2>I &#8211; Running Examples</h2>
<p class="pContent">In order to run any of the examples illustrated in this tutorial, please proceed as follows:</p>
<ol class="numList">
<ol class="numList">
<li>Copy the code and paste it in your favorite text editor &#8211; Notepad will do the job!</li>
</ol>
</ol>
<p class="image"><img src="http://www.clickfire.com/images/img/s1_1.png" alt="Example 1" border="0" /></p>
<ol class="numList">
<ol class="numList">
<li>Save the file as <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">pagename.html</span></span>, you can replace <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">pagename</span></span> by anything you want.</li>
</ol>
</ol>
<p class="image"><img src="http://www.clickfire.com/images/img/s1_2.png" alt="Save the file" /></p>
<p class="image"><img src="http://www.clickfire.com/images/img/s1_3.png" alt="Save the file 2" /></p>
<ol class="numList">
<ol class="numList">
<li>Double click on the file you just saved.</li>
</ol>
</ol>
<p class="image"><img src="http://www.clickfire.com/images/img/s1_4.png" alt="Double click on the file" /></p>
<ol class="numList">
<li>It&#8217;ll be displayed in your default web browser.</li>
</ol>
<h2>II &#8211; The Power of JavaScript</h2>
<p class="pContent">HTML (Hypertext Mark Up Language) is the language of the web by excellence.<br />
To put it simple, HTML allows you to display data and format the way it looks (with the help of CSS).<br />
Check the example that follows:</p>
<h3 class="tTitle">Example 1</h3>
<table class="tCode" style="font-size: 12px; background: #dcdcdc; margin-bottom: 10px; width: 420px; font-family: Times New Roman; border: #000000 1px solid;" border="0">
<tbody>
<tr>
<td class="tCol1">1<br />
2<br />
3<br />
4<br />
5<br />
6<br />
7<br />
8</td>
<td class="tCol2">&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;Example 1&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
Michael is a Computer Wizard!<br />
&lt;/body&gt;<br />
&lt;/html&gt;</td>
</tr>
</tbody>
</table>
<p>In this example, whatever you add to the HTML code and no matter how many time you refresh the page, you will not be able to change the sentence <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">Michael is a Computer Wizard!</span></span>.<br />
What if I wanted to display <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">Mr. X is a Computer Wizard!</span></span> if Mr. X visits the page?<br />
Just by using HTML, this will not be possible.<br />
This illustrates the limits of using simple HTML: data is static, which means it doesn’t change from one situation to another.</p>
<p>To solve this problem, Netscape created JavaScript, a scripting language for the web.<br />
Let us try the HTML code with some JavaScript this time:</p>
<h3 class="tTitle">Example 2</h3>
<table class="tCode" style="font-size: 12px; background: #dcdcdc; margin-bottom: 10px; width: 420px; font-family: Times New Roman; border: #000000 1px solid;" border="0">
<tbody>
<tr>
<td class="tCol1">1<br />
2<br />
3<br />
4<br />
5<br />
6<br />
7<br />
8<br />
9<br />
10<br />
11<br />
12<br />
13</td>
<td class="tCol2">&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;Example 2&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;&#8221;script type=&#8221;text/javascript&#8221;<br />
var name;<br />
name = prompt(&#8220;What&#8217;s your name?&#8221;, &#8220;Your Name&#8221;);<br />
var message = name + &#8221; is a Computer Wizard!&#8221;;<br />
document.write(message);<br />
&lt;/script&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</td>
</tr>
</tbody>
</table>
<p>In this example, the user will enter his name in a prompt box and the message will be displayed.<br />
If Bob enters his name, the message <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">Bob is a Computer Wizard!</span></span> will be displayed.<br />
You don&#8217;t believe me, do you? Try it yourself; the best way to learn is by trial and error&#8230;</p>
<h2>III &#8211; Understanding JavaScript</h2>
<p class="pContent">Before you understand properly how we were able to do that, you must understand some principle of JavaScript.<br />
Contrarily to other programming languages (such as C, C++ or Java) which are mostly used for standalone application, JavaScript is a web-only scripting language (a scripting language is a less complicated programming language).</p>
<h3>JavaScript is also:</h3>
<ol class="unNumList">
<li>Interpreted<br />
No code compilation is required.<br />
The JavaScript code is simply interpreted and executed when the page is opened.<br />
We just typed the code in a HTML file, double clicked on the file, and the browser did the rest for us.</li>
<li>Executed on the client-side<br />
The code is executed in the user&#8217;s browsers when he opens the page.<br />
You can view the code from your browser; this operation differs from a browser to another.</p>
<p class="image"><img src="http://www.clickfire.com/images/img/s2_1.png" alt="Executed on the client-side" /></p>
<p>Actually, the HTML and JavaScript code is visible to any user who opens the page.</li>
<li><strong>NOT</strong> the same as Java<br />
The two programming languages do not share the same creator or the same programming concepts.<br />
They might look similar in some cases, but their programming dialects actually differ.</li>
</ol>
<h2>IV &#8211; JavaScript Essentials</h2>
<p class="pContent">In what follows, we will consider Example 2 as a reference, more particularly this piece of code:</p>
<table class="tCode" style="font-size: 12px; background: #dcdcdc; margin-bottom: 10px; width: 420px; font-family: Times New Roman; border: #000000 1px solid;" border="0">
<tbody>
<tr>
<td class="tCol1">6<br />
7<br />
8<br />
9<br />
10<br />
11</td>
<td class="tCol2">&lt;script type=&#8221;text/javascript&#8221;<br />
var name;<br />
name = prompt(&#8220;What&#8217;s your name?&#8221;, &#8220;Your Name&#8221;);<br />
var message = name + &#8221; is a Computer Wizard!&#8221;;<br />
document.write(message);<br />
&lt;/script&gt;</td>
</tr>
</tbody>
</table>
<ol class="unNumList">
<li>
<p class="pSubTitle">The <span class="lCode"><span style="font-size: x-small; font-family: Times New Roman; background-color: #dcdcdc;">&lt;script&gt;</span></span> tag</p>
<p>Except the content within the <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">script</span></span> starting (line 6) and ending (line 11) tags, the code is simple HTML which you are probably very familiar with.<br />
Any JavaScript code written within our HTML must be preceeded by <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">&lt;script type=&#8221;text/javascript&#8221; </span></span>and succeeded by <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">&lt;/script&gt;</span></span>.</li>
<li>
<p class="pSubTitle">Declaring a variable</p>
<p>In JavaScript, a variable is an element that stores data. Data can be anything: an integer (eg. <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">14</span></span>), a decimal number (eg. <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">0.4</span></span>), a character (eg. <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">&#8216;J&#8217;</span></span>), a string (eg. <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">&#8216;I hate brocolli&#8217;</span></span>), or any other data type.<br />
To declare a variable we use the following format: <span style="background-color: #dcdcdc;"><span style="font-family: Times New Roman;"><span class="lCode">var &lt;variable_name&gt;;</span><br />
</span></span>The <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">&lt;variable_name&gt;</span></span> must start by either a letter or an underscore (<span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">&#8216;_&#8217;</span></span>) and can only contain letters, numbers or the underscore character.</p>
<p>In our example, we declared two variables:<br />
<span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">var name</span></span> on line 7<br />
<span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">name</span></span> is used to store the name of the person (eg. <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">&#8216;Michael&#8217;</span></span>)<br />
<span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">var message</span></span> on line 9<br />
<span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">message</span></span> is used to store the message to output (eg. <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">&#8216;Michael is a Computer Wizard!&#8217;</span></span>)</li>
<li>
<p class="pSubTitle">The Prompt Box</p>
<p>JavaScript has three different built-in popup boxes: the alert box, the confirm box and the prompt box.<br />
A prompt box displays a message, an <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">&#8216;OK&#8217;</span></span> button, a <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">&#8216;Cancel&#8217;</span></span> button and prompts the user to input data.<br />
It is called in this format: <span style="background-color: #dcdcdc;"><span style="font-family: Times New Roman;"><span class="lCode">prompt(&lt;display_message&gt;, &lt;default_data&gt;);</span><br />
<span class="lCode">&lt;display_data&gt;</span></span></span> is the message to display to the user.<br />
<span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">&lt;default_data&gt;</span></span> is the default value entered by the user.<br />
The <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">prompt</span></span> function returns the value entered by the user once he clicks the <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">&#8216;OK&#8217;</span></span> button.<br />
If he clicks the <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">&#8216;Cancel&#8217;</span></span> button instead, <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">null</span></span> is returned.</p>
<p>In our example, we used a prompt box on line 8: <span style="background-color: #dcdcdc;"><span style="font-family: Times New Roman;"><span class="lCode">prompt(&#8220;What&#8217;s your name?&#8221;, &#8220;Your Name&#8221;);</span><br />
<span class="lCode">&#8220;What&#8217;s your name?&#8221;</span></span></span> is the <span style="background-color: #dcdcdc;"><span style="font-family: Times New Roman;"><span class="lCode">&lt;display_data&gt;</span><br />
<span class="lCode">&#8220;Your Name&#8221;</span></span></span> is the <span style="background-color: #dcdcdc;"><span style="font-family: Times New Roman;"><span class="lCode">&lt;default_data&gt;</span><br />
</span></span>You notice, in the example, <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">&#8216;Your Name&#8217;</span></span> is entered in the prompt box when the page first loads.</p>
<p>Assuming the user enters <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">&#8216;Bob&#8217;</span></span> and clicks the <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">&#8216;OK&#8217;</span></span> button, the variable <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">name</span></span> will have the value <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">&#8216;Bob&#8217;</span></span> after line 8.<br />
In this case the message <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">&#8216;Bob is a Wizard!&#8217;</span></span> will be output.<br />
Assuming the user clicks the <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">&#8216;Cancel&#8217;</span></span> button, the variable <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">name</span></span> will have the value <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">null</span></span> after line 8.<br />
In this case the message <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">&#8216;null is a Wizard!&#8217;</span></span> will be output. Try it yourself&#8230;</li>
<li>
<p class="pSubTitle">Strings</p>
<p>In programming languages, a string is any sequence of characters (eg. <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">&#8216;Duh!&#8217;</span></span>, <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">&#8216;Chi huaha&#8217;</span></span>). A string can also be empty (eg. <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">&#8221;</span></span>).<br />
In JavaScript there is no specific data type called string.<br />
There is only one data type called <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">var</span></span>, a variable (which we discussed earlier).<br />
In a variable, we differentiate a string from other data types by using single quotations or double quotations on both side of the value.<br />
<span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">var bob1 = &#8220;Bob rules&#8221;;</span></span> Valid string assignment.<br />
<span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">var bob2 = &#8216;Bob rules&#8217;;</span></span> Valid string assignment.<br />
<span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">var bob3 = &#8216;Bob rules&#8221;;</span></span> Invalid string assignment: a single quotation on one side and a double quotation on the other.</p>
<p>Strings can also be concatenated together: that is two or more strings can be attached together to form a new string.<br />
To achieve this, we use the <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">&#8216;+&#8217;</span></span> operator. The operator is also used with other data types; what you need to know for the moment is that when <strong>used with strings</strong>, the <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">&#8216;+&#8217;</span></span> operator concatenates.<br />
<span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">var bob4 = bob1 + bob2;</span></span> Valid string assignment. <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">bob4</span></span> will have the value <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">&#8220;Bob rulesBob rules&#8221;</span></span>.<br />
<span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">var bob5 = bob1 + &#8221; i tell you, &#8221; + bob1;</span></span> Valid string assignment. <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">bob5</span></span> will have the value <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">&#8220;Bob rules i tell you, Bob rules&#8221;</span></span>.<br />
<span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">var bob6 = bob1 + &#8221; but I am&#8221; + &#8221; da King!&#8221;;</span></span> Valid string assignemnt. <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">bob6</span></span> will have the value <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">&#8220;Bob rules but I am da King!</span></span>.<br />
<span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">var bob1 = bob1 + &#8220;: this is not true!&#8221;;</span></span> Not valid string assignment: <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">bob1</span></span> is already declared.<br />
<span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">bob1 = bob1 + &#8220;: this is not true!&#8221;;</span></span> Valid string assignment. <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">bob1</span></span> will have the value <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">&#8220;Bob rules: this is not true!&#8221;</span></span>.</p>
<p>Now that you became familiar with variables and particularly strings, examine these lines of code once again:</p>
<table class="tCode" style="font-size: 12px; background: #dcdcdc; margin-bottom: 10px; width: 420px; font-family: Times New Roman; border: #000000 1px solid;" border="0">
<tbody>
<tr>
<td class="tCol1">7<br />
8<br />
9</td>
<td class="tCol2">var name;<br />
name = prompt(&#8220;What&#8217;s your name?&#8221;, &#8220;Your Name&#8221;);<br />
var message = name + &#8221; is a Computer Wizard!&#8221;;</td>
</tr>
</tbody>
</table>
<p>On line 8, <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">name</span></span> is assignned the data entered by the user.<br />
On line 9, <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">message</span></span> is assigned the data entered by the user (eg. <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">Bill</span></span>), concatenated with the string <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">&#8216; is a Computer Wizard!&#8217;</span></span> producing a new string (eg. <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">&#8216;Bill is a Computer Wizard!&#8217;</span></span>).</li>
</ol>
<h2>V &#8211; From JavaScript to HTML</h2>
<p class="pContent">In order to output, from JavaScript, data to the HTML code, we use the function <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">document.write</span></span>.<br />
The function is called in this format: <span style="background-color: #dcdcdc;"><span style="font-family: Times New Roman;"><span class="lCode">document.write(&lt;output_data&gt;);</span><br />
<span class="lCode">&lt;output_data&gt;</span></span></span> is the data to output to HTML.</p>
<table class="tCode" style="font-size: 12px; background: #dcdcdc; margin-bottom: 10px; width: 420px; font-family: Times New Roman; border: #000000 1px solid;" border="0">
<tbody>
<tr>
<td class="tCol1">10</td>
<td class="tCol2">document.write(message);</td>
</tr>
</tbody>
</table>
<p>In Example 2, we used <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">document.write(message);</span></span> on line 10.<br />
This outputs the value of <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">message</span></span> to HTML.</p>
<p>Let us consider some new examples in order to understand more the <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">document.write</span></span> function.</p>
<h3 class="tTitle">Example 3</h3>
<table class="tCode" style="font-size: 12px; background: #dcdcdc; margin-bottom: 10px; width: 420px; font-family: Times New Roman; border: #000000 1px solid;" border="0">
<tbody>
<tr>
<td class="tCol1">1<br />
2<br />
3<br />
4<br />
5<br />
6<br />
7<br />
8<br />
9<br />
10<br />
11</td>
<td class="tCol2">&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;Example 3&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;script type=&#8221;text/javascript&#8221;&gt;<br />
var something = &#8220;Hello There&#8221;;<br />
document.write(something);<br />
&lt;/script&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</td>
</tr>
</tbody>
</table>
<p><span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">&#8220;Hello There&#8221;</span></span> will appear on our HTML page.<br />
We can actually rewrite this page in simple HTML, which will produce the exact same result. The code is as follows:</p>
<h3 class="tTitle">Example 3 Bis</h3>
<table class="tCode" style="font-size: 12px; background: #dcdcdc; margin-bottom: 10px; width: 420px; font-family: Times New Roman; border: #000000 1px solid;" border="0">
<tbody>
<tr>
<td class="tCol1">1<br />
2<br />
3<br />
4<br />
5<br />
6<br />
7<br />
8</td>
<td class="tCol2">&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;Example 3 Bis&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
Hello There<br />
&lt;/body&gt;<br />
&lt;/html&gt;</td>
</tr>
</tbody>
</table>
<p>Now, how about this example:</p>
<h3 class="tTitle">Example 4</h3>
<table class="tCode" style="font-size: 12px; background: #dcdcdc; margin-bottom: 10px; width: 420px; font-family: Times New Roman; border: #000000 1px solid;" border="0">
<tbody>
<tr>
<td class="tCol1">1<br />
2<br />
3<br />
4<br />
5<br />
6<br />
7<br />
8<br />
9<br />
10<br />
11<br />
12<br />
13</td>
<td class="tCol2">&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;Example 4&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;script type=&#8221;text/javascript&#8221;&gt;<br />
var title = &#8220;1984&#8243;;<br />
var author = &#8220;by George Orwell&#8221;;<br />
document.write(&#8220;&lt;b&gt;&#8221; + title + &#8220;&lt;/b&gt;&#8221; +<br />
&#8220;&lt;br /&gt;\n&#8221; + &#8220;&lt;i&gt;&#8221; + author + &#8220;&lt;/i&gt;&#8221;);<br />
&lt;/script&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</td>
</tr>
</tbody>
</table>
<p>The output of the page will be: <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">1984</span></span> in bold, then a line break, then <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">by George Orwell</span></span> in italic.<br />
You can span several lines when dealing with a string (such as on line 9-10) by using the <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">&#8216;+&#8217;</span></span> operator then continuing on the next line.<br />
The <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">&#8216;\n&#8217;</span></span> (on line 10) is used to create a new line in the output process of the HTML code. That is, a line break will exist after the <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">&lt;br /&gt;</span></span> tag.<br />
The equivalent simple HTML version of Example 4 is as follows:</p>
<h3 class="tTitle">Example 4 Bis</h3>
<table class="tCode" style="font-size: 12px; background: #dcdcdc; margin-bottom: 10px; width: 420px; font-family: Times New Roman; border: #000000 1px solid;" border="0">
<tbody>
<tr>
<td class="tCol1">1<br />
2<br />
3<br />
4<br />
5<br />
6<br />
7<br />
8<br />
9</td>
<td class="tCol2">&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;Example 4 Bis&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;b&gt;1984&lt;/b&gt;&lt;br /&gt;<br />
&lt;i&gt;by George Orwell&lt;/i&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</td>
</tr>
</tbody>
</table>
<p>You now observe how powerful the <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">document.write</span></span> function is.<br />
You can output to HTML anything even HTML tags or even JavaScript code (within <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">&lt;script&gt;</span></span> and <span class="lCode"><span style="font-family: Times New Roman; background-color: #dcdcdc;">&lt;/script&gt;</span></span> tags) to be executed.</p>
<p>Still, there&#8217;s much more to JavaScript than just printing HTML. Maybe some other time&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.clickfire.com/starting-with-javascript-tutorial/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

