This is the first part of my series, JavaScript Basics. JavaScript is a scripting language that operates at the web client's computer in the browser. This is the third series I am writing which prepares you as a web site designer. You need just three of the series to be a good web site designer. The first one I wrote is, XHTML Basics. XHTML is like the latest version of HTML, today. The second one is, Basics of CSS2. CSS2 is the latest version of CSS, today. And this is the third one, JavaScript Basics. If you complete these three series, you will be able to design good web sites.
Note: If you cannot see the code or if you think anything is missing (broken link, image absent), just contact me at forchatrans@yahoo.com. That is, contact me for the slightest problem you have about what you are reading.
Purpose of JavaScript
HTML or XHTML gives you a functional web page. CSS makes the web page presentable. JavaScript makes the web page interactive. Now, with HTML and CSS your web page will be able to serve your users or customers. However, you might want that when you click a button on the page some text should appear on the page immediately, without being downloaded. You might also want that when the user types into the field of a Form, an alert box should pop up if the user made an error, indicating that the user made an error. These two objectives and many others are not offered by HTML and CSS. You need a browser scripting language, such as JavaScript for that.
Prerequisite
In order to study JavaScript, you should have basic knowledge XHTML (or HTML) and Cascaded Style Sheet (CSS). If you have not studied these languages, then you should study them from the series I wrote in this blog (or another blog in my name). To arrive at the XHTML series I wrote, type, "XHTML Basics" and my name, "Chrys" in the Search box of this page and click Search. If you have a Google Search box on this page, use it. To arrive at the CSS series I wrote type, "Basics of CSS2" and my name, "Chrys" in the Search box of this page and click Search. If you have a Google Search box on this page, use it.
Also, in order to study JavaScript, your level of mathematics should be at least that of Middle School. If you went through middle school and did not pass in mathematics, you may manage to understand my series, but I strongly advise you to do a Middle School mathematic course. Do it at, http://www.cool-mathematics.biz . This site offers online interactive middle school math course in a step-by-step fashion, in as short as three months or as long as 10 months. There, you have the right to ask questions from the authors of the web site. You can be studying the math course while studying JavaScript.
Requirements to Study JavaScript
Here, I give you the requirements to study JavaScript from my series.
- A Personal Computer with its operating sysytem
- A Browser
- A text editor
In this series there are many code samples that you will be trying (with your browser). The JavaScript code is part of your web page.
Your First JavaScript Code
This is the script:
document.write('Hello World!');
Script Explanation
XHTML or HTML has a double tag element called, the SCRIPT element. If the tags of the script are typed without errors, you do not see the content of the tags in the HTML document at the browser. There is one important attribute that must go into the start tag of the SCRIPT element. This is the, type, attribute. The value of this attribute should be "text/javascript" as in the code above. It means the script contains JavaScript text, instead of text of some other scripting language.
The script element above has just one line of code. This line of code ends with a semicolon. In the line the first word you have is "document". This is followed by a dot, then the word, "write". You must type those two words in that order and in lowercase. You must have the dot in-between the two words.
After the word, "write" you have a pair of parentheses (opening and closing brackets). Inside the parentheses you have the phrase, 'Hello World!' in single quotes. This line, as it is, is called a statement. It prints the phrase, 'Hello World!' on the web page. The phrase can be in single quotes or double quotes.
Testing the Script
The following is the above script in an XHTML document:
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
document.write('Hello World!');
Copy and past the whole code in an empty text editor window. Save the file in a directory, giving it a name with an HTML extension, that is .htm or .html. Open the file in your browser (File|Open) and you should see 'Hello World!' displayed as the only content.
That is it for this part of the series. We continue in the next part of the series.
Chrys
Published by Chrys Forcha
I have more than 10 years experience in computer programming, software, electronics and telecommunications. I have a First Degree in Electronics and a Master's Degree in Technical Education. As well a... View profile
- Basics of JavaScript VariablesIn this part of the series, I explain the meaning of JavaScript variables.
- Boolean Logic and JavaScript ConditionsIn this part of the series we apply Boolean logic to JavaScript conditions.
- JavaScript Loop StatementsIn JavaScript, you have the do-while loop, the while loop and the for loop. We shall see what all these mean in this article.
- How to Use Strengths-Based Management to Attract Top PerformersThe purpose of this article is to discuss how an organization might effectively use strengths based management in recruiting and selecting high performers.
- Introduction to JavaScript String Regular ExpressionsIn this article I explain the meaning of Regular Expressions and I introduce you to the concept with the JavaScript String object. You start learning what is called Matching.
- What Programming Language to Start With
- Basics of CSS Selectors
- Getting Started with CSS2
- JavaScript Function Basics
- JavaScript Array
- JavaScript Object Basics
- JavaScript Outputs
