How to write a Simple Java Script for Web Programming

Javascript Image

Brief Overview of JavaScript

In this post ,I discuss what is the necessary of JavaScript in web programming and how it influences the website design and other application development.

In the previous posts of my blog, I discussed how to use the HTML to create a website and using bootstrap4 for improving the look and feel of the website and reducing the stress of web designer .

Why JavaScript ?

The first question come to our mind is why we require Javascript to our webpage ? The answer is simple to provide the computing ability for the webpage ,we use the scripting language. The markup language like HTML and XML will help to design the webpage but by using them we cannot perform any computation but incorporating the scripting language we ca provide that facility for the web pages.

This facility changes the web page functionality and future of the internet programming means web pages not only display the content but also provide computation.

What is the difference between programming language and scripting language ?

Programming language Scripting language
Require CompilationDo not require compilation
Static in natureDynamic in nature
Debugging is difficultdebugging is easy.
Datatype need to be defined.No need defining Datatype during declaration.
Ex: C, C++Ex: JavaScript,PHP

Now we clarified the doubt about scripting language ,if you want more details about it ,click here.

What is Java Script ? What is its History?

Javascript previously called as live script ,first appeared in December 4 1994, It conforms to ECMA script specification , Javascript is a high level ,just in compiled scripting language .It has object orientation and first class function support.

Like HTML and CSS, Javascript is also core technology of the WWW. Javascript enables interactive webpages and it is important part in web application. Usually the javascript is used only for client side scripting compared to server side scripting, in future post.

I will discuss what is client side ans server side scripting . Means the browser can readily execute the javascript without the installation of compiler . Means the browser like mozila and chrome comes with inbuilt javascript engines. In chrome it is called “V8” , in Mozila “Spidermonkey” and similarly for internet explorer in windows called “Chakra”. The more history about Javascript can be found here.

How to Include JavaScript in the HTML?

The javascript can be included to our web pages in two ways :

  1. Using Script tag: The <script> is paired tag will be used to place the scripting code inside the HTML .This is called internal .
  2. Using link attribute in script tag : another way is create a separate file called file.javascript and provide the path name of that file inside the script tag.

The script tag informs HTML that it contains the scripting code to be executed before displaying the web page.

Now we have all the information to create a simple javascript, which displays the information “hello world”

Javascript Examples

The above html code display the Hello world using the javascript code, we used the document.write method to finish the above task , means document .write () works exactly as printf() in C programming language.

Let us take one more example to do arithmetic operation:

The above example illustrate the use of arithmetic operation using Javascript . In this example we used some constructs of scripting language : var is used to define the variable , whether it is an integer or any type , in scripting language. there is no need to specify the datatype ,as I already discussed above .

I will conclude this post here, I will discuss advanced features of JavaScript in future post ,please give your reply to this , try this code in your laptop or PC and see the result.

Scroll to Top