JavaScript Basics

Basics of JavaScript

This article was created to outline the basics of the JavaScript langauge.

JavaScript – Unsupported Browsers

When JavaScript is run in an unsupported browser, the script itself might be displayed as text within the browser. To prevent this from happening, it is best to use the HTML comment feature to comment out the code from the script.

For example:
<SCRIPT TYPE="text/javascript">

JavaScript program

HTML is commented out as follows:
<!– This line is commented out
So is this one.
End of comment –>

It also might be a good idea to use a JavaScript comment to remove text from the script itself, yet allowing the comment to be displayed within the HTML of a page.

For example:
<SCRIPT TYPE="text/javascript">
// JavaScript Script Appears Here <BR />
// Download a
compatible browser to use it.

The lines with // remove the text from the JavaScript but not from the HTML.
Lines inclosed with the <!-- and --> brackets remove the script from the HTML but not from the script interpreter. The above example will simply notify the user that there browser does not support JavaScript, in the event this is the case. If the browser does support JavaScript, the script will work as it should.

Up to date browsers use the <NOSCRIPT>  </NOSCRIPT>  tag to alert the user that their browser does not support JavaScript. For a website to be completely accessible, the <NOSCRIPT> tag must be used in every instance of <SCRIPT TYPE="text/javascript>.

Also note, that current day HTML/XHTML standards define that scripts should be defined without the use of capitalization. For purposes of this article, the <SCRIPTS> are capitalized for reference purposes only.

Also be aware that the use of commenting out a JavaScript will also remove the Script if one is using XHTML. To avoid any problems, the <NOSCRIPT> tag should be used.


JavaScript Source Attribute

In instances when a JavaScript may be extensive, the script is often stored in an external JavaScript file (scriptfile.js). The script can be called upon with use of the <SCRIPT TYPE="text/javascript"
</SCRIPT> script.

JavaScript Objects

The window object provides methods and properties for dealing with the actual Navigator window, including objects for each frame.

The location object provides properties and methods for working with the currently open URL.

The history object provides information about the history list and enables limited interaction with the list.

The document object is one of the most heavily used objects in the hierarchy. It contains objects, properties, and methods for working with document elements including forms, links, anchors, and applets.

The string object enables programs to work with and manipulate strings of text, including extracting substrings and converting text to upper- or lower-case characters.

The Math object provides methods to perform trigonometric functions, such as sine and tangent, as well as general mathematical functions, such as square roots.

With the Date object, programs can work with the current date or create instances for specific dates. The object includes methods for calculating the difference between two dates and working with times.

  Related Posts