JavaScript Programming Language – What is a JavaScript Program

It’s been a long time there has not been any update on my blog, today I got some time and want to cover what is meant by JavaScript! Let’s get into it 🙂

What is a JavaScript?

JS (short for JavaScript) is a fantastic programming language. JavaScript programming language brings magic in programming world, for example, if you want to update a page or show information without page reload, you will use AJAX (which is based on JS), if you want to validate a form, you use JS, and so on.

The biggest benefit of JavaScript programming is that it is not server side language, which means, everything you code in JS will run on users’ computer. This will allow you to execute necessary tasks on users’ browser rather than sending data to server and putting on load on it. This also makes information processing more secure, since the processing only occurs on users’ computers.

 Note: JS support is built into most of the modern browsers. You just have to ensure it is not turned off.

TIP: There are plenty of pre-written Java scripts that you can add to your code.

What is JavaScript for?

As mentioned earlier, you can use it for any purpose but here are some of the examples,

·      You can add certain behaviour to your static web page such as interact with your website     visitors without page reload. For examples, when your user fills out a form and clicks on submit button, page reload will no longer will required. This improves your user experience as well.

·      Form validation, before the data is send to server, you can check if the form is properly filled or not. You can check fields for data that can be used for hacking etc. and remove it before it is send to server.

·      Implement quick search such as a search box that shows you results as you type in

·      Pre filled form content

·      Since you can create a logic, you can play with the design of page or make it responsive by using JS. By using JS, you can check the size and placement of design elements and change it accordingly for different screen sizes. You can show or hide certain items on page based on user input and o many more.

·      Add animations: for SEO this is the most recommended way of adding animations to your site.

CSS, HTML and JavaScript – Where to put them in a file?

Many Programmers follow the practice of putting everything in one file, even PHP code. This makes it hard to troubleshoot and a ‘not good’ practice.  The best practices are to have separate files for CSS, JS and HTML.

How to recognise JavaScript code?

If you are viewing the code of a web page and want to find out where is JavaScript, the first thing you should check for is the following tag,

JS code is normally added in the head section of web page but you can place it anywhere. Previously, we used the following syntax when writing JS code,

But these days, our browsers are quite intelligent and they can recognise JS code so we can only use <script></script> tags.

Example JavaScript Program:

Above syntax is to be used when you are writing JS code within HTML file. If you have a separate JS file, then you can easily include it into your HTML file without having to write code in it,

There are couple of other ways to add JS code but they are not recommended such as adding JS code in HTML tags like,

on the other hand, you can insert JS code in href attribute like;

Program in JavaScript – Example code to read URL properties

Above example explains the usage of document object model through which we can access the properties of any object. By clicking on anchor text “Click me”, the script will show URL that is

You can also use a short form of accessing properties and that is;

Differences in Microsoft version of JavaScript

Microsoft version of JavaScript, which is called Jscript, has slight differences from standard JS. Microsoft Internet explorer will not allow you to access child elements of parent DOM, so in case you want to fetch properties of any element through ‘ID’, you will have to use the function ‘getElementById()’, e.g.

Instead of;

you should use,

now your code will run on Internet explorer as well.

Strange Usage of $ Symbol

Sometimes, you will see following code to access properties of ‘ID’ element,

since $ is allowed in JS, programmers normally write a separate function to replace $ with getElementById() e.g.

This will also make coding faster. Therefore, $(‘mylink’).href will be replaced with    document.getElementById(‘mylink’).href

Final Words:

In the next post on JS, we will discuss some advance features of JS along with practical examples. Stay in touch guys, please drop your comments and let me know if you are looking for something that i missed in this post.

  • December 21, 2016
  • 0
Sohail ahmed
About me

Love to train and learn. SEO and development is my profession. 10+ years of IT training, practical experience in SEO. Creativity helps me strategize things well, especially when i code.