Introduction to JavaScript Programming
By Stephen Bucaro
JavaScript is a wonderful little programming language. It's a client-side scripting language,
client-side meaning it runs right on your local computer, not on the web server, and
scripting language meaning it's run by an interpreter. The fact that it's a client-side
scripting language makes it very easy to learn.
In the beginning of the Internet all programs ran on the Web server. The server would
send a webpage to your browser and that was it. It was a static webpage. In order to change
anything on the webpage, the web server had to send another page. Now, with JavaScript
you can perform calculations, play games, totally redo an entire webpage without ever
receiving another webpage from the Web server.
In the old days, all programs were compiled. You would write the entire program,
then submit it to a compiler program which would convert the program to machine code so
it could be run on the computer. If you had an error in your code, you had to correct the error
and resubmit your program to the compiler. JavaScript is an interpreted language.
That means you can write one statement, basically one line of code, run it, see what happens,
then write another statement, run it, see what happens, and so on.
When applications run on the Web server, if you have lots of people using the application,
it will consume lots of server resources. This can cause the server to bog down and the
application to run slow. JavaScript allows you to off-load most, if not all, of an application's
processing to the users Web browser. If ten thousand people are using your application, you
have to serve up ten thousand webpages, but you don't have to run ten thousand program
sessions on your Web server, you can off-load that processing to the users computers.
Today, web servers have lots more power than they did in the old days. Now each web
server can have dozens of processors and vast amounts of memory. If you run your application
on the web server, you have better control of security. Javascript is no way a secure language.
For these reasons many web applications are now moving back to the web server. But for
parts of an application that don't need security, it's still more efficient to off-load those
parts to run JavaScript on the users computers.
As you may know, webpages are codded with Hypertext Markup Language (HTML) tags.
Just about everything you see on a webpage was defined using HTML tags. JavaScript and
HTML work very smoothly together. The elements coded with HTML tags execute events
that can call JavaScript functions. And the JavaScript functions can make changes to
the HTML elements. With the latest version of HTML, you can even use storage areas on the
user's computer, which was not possible until now (except for tiny files called "cookies"
which have been around for a while).
The symbiotic relationship with HTML gives JavaScript lots of power. Throw in some other
webpage technologies like Extensible Markup Language (XML), which can be used to create
databases, and canvas, which allows JavaScript to draw on the webpage, and WebGL which
creates 3D graphics in the browser, and you've got mind blowing power.
Now that I've got you excited, just how do you get started with this amazing technology?
The amazing thing is, it's all done with text that you can type into your text editor. That's
right, JavaScript is text that you can type yourself. Even advanced technologies like XML
and WebGL are text that you can type yourself.
That's not to say that you can't use a fancy What You See Is What You Get
(WYSIWYG) application to create any of the above mentioned coding for you. And sometimes
using a fancy WYSIWYG application is the most efficient method, but the problem is,
most people spend so much time learning how to use the WYSIWYG application interface
that they never learn the basic code. Then when their fancy WYSIWYG application won't
do what they want, they're stuck, because they don't understand the underlying code that
the application creates.
My advise is to first learn to code by hand, and even if you eventually decide to move to
a WYSIWYG application, keep learning new things to do by hand coding. Otherwise you'll
eventually end up joining those people who started with and stuck with a fancy WYSIWYG
application and are now sitting there dumbfounded because they can't fix an error on their
webpage or they can't get it to do what they want.
|