The Basics of Web Development: Part III
This part of the article series will cover one of the client-side languages, JavaScript. The next will be an introduction to relational database management systems (RDBMS), SQL in particular.
JavaScript
File extension: .js
JavaScript is a programming language, its most common usage is enriching webpages by making them interactive. Although it is not the sole objective of JavaScript, it makes sense to only examine this part of JavaScript for our purposes. In that regard, the main goal of JavaScript (in our context) is to manipulate elements of the DOM model of a webpage.
Let's take a brief look at what DOM is.
The DOM (stands for Document Object Model) is a convention, a platform- and language- neutral programming API for representing and interacting with objects in documents. DOM requires a document (such as a webpage) to be implemented as a tree of nodes (objects) that have certain attributes, which can be changed through the following manipulations:
-
getting nodes;
-
changing nodes;
-
changing the relation between nodes;
-
deleting nodes.
These exact manipulations can be performed by means of the JavaScript language.
In order to add a JavaScript code to a page you must use the “script” tag. It is recommended to put this tag inside the “head” tag, although that's not necessary.
The number of script containers per document is unlimited. The “type='text/javascript'” attribute is not a must, since it's already the default value.
Below is a sample script, which outputs the so-called modal window with the well-known “Hello, World!” text in a browser:
<script type="text/javascript>
alert('Hello, World!');
</script>
It is safe to conclude that JavaScript is a language which allows us to actively control the structure of our webpage and manipulate its elements.
In practice, it can be used to apply different animation effects to objects, such as dissolution, movement, zooming in and out, etc.
It is also widely used for implementing photo galleries or, for example, sliders/rotators of content whose purpose is to visualize the alternation of objects (say, images) within a limited space area.
Quite often JavaScript is used for the first-level verification of the data the user fills in a form.
Since we are talking about JavaScript, it would've been almost inappropriate to forget to mention JavaScript libraries (jQuery, MooTools, Prototype, etc.) These libraries provide a cross-browser interface for DOM methods. What it means is that by using such a library you can free yourself from the necessity of writing something that's already been written, tested and proven to work on all browsers. It also means that you don't have to know JavaScript in too much detail, you can just use the convenient instruments and interface these libraries have to offer.
JavaScript can add something new, original and fun to your website, both visually and programmatically.