Tuesday, 10 March 2015

Introduction to JavaScript

For newbies into programming and oldies in the game, JavaScript is a web client-sided programming language used for developing applications that run directly on a web-browser and functions independently of the web-server.


All major web-browsers come pre-installed with Javascript interpreter so there is not much you really need to do get JavaScript codes up and running on your website. 

NOW! a major information to note here.. JavaScript is not Java.  They share the same first four characters but they are different languages. Java predates JavaScript. Java became really popular in the 1990's as a computer programming language. Developers of JavaScript really needed a name to push the language, thus JavaScript.


JavaScript is considered an Object Oriented Programming language to a degree. The concepts of inheritance, polymorphism and encapsulation are not fully in use in the language. It does make use of objects though. This we will explore in future write-ups.


JavaScript, like all languages of the world have rules of engagement. Means, to effectively communicate your needs to the web-browser, these rules must be adhered to to the dot. Some of these include.

1. JS sentences terminate with a semi-colon - Just like a sentence in English ends with a full-stop(.), JavaScript terminates its sentence with a semi-colon (;). Take a look at the JS statement below,
alert("Hi there");

Notice the termination symbol at the end of the sentence above. If your statement is not terminated properly, JS may just choose to not work. I battled with this very rule years back as a newbie into programming. Hundreds of lines of code would just not work for failing to put in a little silly semi-colon (;) in its appropriate place. The symbol can make or mar your script basically. You want to be really careful here.

2. JS is case-sensitive - You really want to watch this one too. You will find yourself committing the same case-sensitivity mistake over and over and yes, they can rubbish your entire script.

alert() and Alert() are different.
window.onload() and window.onLoad() are also very different

The JS function alert() begins with a lowercase letter "a". Replacing the small case "a" with an uppercase letter "A"; i.e Alert(); you would have created a bug in your script and your javascript code will not work.

There are loads of functions, classes and methods that come in-built with your web-browser. They all require that you call and use them exactly as they were created.

3. JS statements are written inside HTML script opening and closing tags.

<script>
//Javascript statements here
</script>

JavaScript statements cannot be defined outside of HTML script tags. That is the only area in which your JS statements can be created for it to be processed by the JS interpreter. 

These are three major rules that have to be followed to work with JavaScript.

Joseph Kayode Agbede

1 comment: