JavaScript

This section will provide you with the basics of what JavaScript is, and why you should use it.

Objectives     JavaScript versus JAVA     Interpreted programs versus Compiled programs     Why JavaScript     What you can use JavaScript for     About JavaScript JavaScript is a lightweight, interpreted programming language. It is designed for creating network-centric applications. It is complimentary to and integrated with Java. JavaScript is very easy to implement because it is integrated with HTML. It is open and cross-platform.

What is JavaScript ?

Javascript is a dynamic computer programming language. It is lightweight and most
commonly used as a part of web pages, whose implementations allow client-side
script to interact with the user and make dynamic pages. It is an interpreted
programming language with object-oriented capabilities.

JavaScript was first known as LiveScript, but Netscape changed its name to
JavaScript, possibly because of the excitement being generated by Java.
JavaScript made its first appearance in Netscape 2.0 in 1995 with the name
LiveScript. The general-purpose core of the language has been embedded in
Netscape, Internet Explorer, and other web browsers.

The ECMA-262 Specification defined a standard version of the core JavaScript language.

JavaScript is a lightweight, interpreted programming language.

Designed for creating network-centric applications.

Complementary to and integrated with Java.

Complementary to and integrated with HTML.

Open and cross-platform

JavaScript versus JAVA

JAVA is a strongly typed, compiled programming language developed by Sun Microsystems. JavaScript, developed originally by Netscape, is a lightweight, interpreted programming language initially called LiveScript. The two languages are not related in any way. All programming languages share a certain amount of similarity.

Why Learn JavaScript

JavaScript is the only scripting language currently supported by the popular web browsers. Netscape Navigator only supports JavaScript, whereas Microsoft Internet Explorer supports both JavaScript and VBScript. JavaScript can also be used on web servers for what’s called server side scripting as well. The time you invest into learning the JavaScript language will provide you with what is now considered to be a core skill for web development.

 

Limitations of JavaScript

We cannot treat JavaScript as a full-fledged programming language. It lacks the following important features −

  • Client-side JavaScript does not allow the reading or writing of files. This has been kept for security reason.
  • JavaScript cannot be used for networking applications because there is no such support available.
  • JavaScript doesn’t have any multithreading or multiprocessor capabilities.

Once again, JavaScript is a lightweight, interpreted programming language that allows you to build interactivity into otherwise static HTML pages.

JavaScript Development Tools

One of major strengths of JavaScript is that it does not require expensive development tools. You can start with a simple text editor such as Notepad. Since it is an interpreted language inside the context of a web browser, you don’t even need to buy a compiler.

To make our life simpler, various vendors have come up with very nice JavaScript editing tools. Some of them are listed here −

  • Microsoft FrontPage − Microsoft has developed a popular HTML editor called FrontPage. FrontPage also provides web developers with a number of JavaScript tools to assist in the creation of interactive websites.
  • Macromedia Dreamweaver MX − Macromedia Dreamweaver MX is a very popular HTML and JavaScript editor in the professional web development crowd. It provides several handy prebuilt JavaScript components, integrates well with databases, and conforms to new standards such as XHTML and XML.
  • Macromedia HomeSite 5 − HomeSite 5 is a well-liked HTML and JavaScript editor from Macromedia that can be used to manage personal websites effectively.
  • Interpreted programs versus Compiled programs
  • Before we start discussing the differences between interpreted and compiled we have to define the term source code or as it is more commonly referred to, the code. The code is the plain text commands that the program is written in. All programming languages start out as source code, it is then either interpreted or compiled. The code that you will create in this course can be considered source code.
  • Interpreted programming languages tend to be simpler to program but slower to execute in general. Each time a program is run it has to be interpreted (interrogated) line by line, based on the flow of execution (you will see later branches and loops affect the flow of execution).
  • Compiled programming languages have a more complex syntax, and require more strict programming practices. With a compiled programming language you first write the source code, then you feed it to a compiler (a special computer program) which produces an executable binary program. On the Windows platforms the output of the compiler usually ends in the “.exe” file extension. The program that comes out of the compilation process tends to be platform (operating system) specific. The key benefit for the programmer is that no other programmer can look at the source code once it is compiled. The other key factor is that the language used to write the source code becomes irrelevant once it has been compiled.
  • JAVA is a compiled language that is platform independent, whereas JavaScript is an interpreted language. The browser provides the platform independence for JAVA through its JAVA Virtual Machine, and the interpreter for JavaScript. As a result, the browser you are writing your scripts for is important.

JavaScript can be implemented using JavaScript statements that are placed within the <script>… </script> HTML tags in a web page.

You can place the <script> tags, containing your JavaScript, anywhere within you web page, but it is normally recommended that you should keep it within the <head> tags.

The <script> tag alerts the browser program to start interpreting all the text between these tags as a script. A simple syntax of your JavaScript will appear as follows.

<script …> JavaScript code</script>

The script tag takes two important attributes −

  • Language− This attribute specifies what scripting language you are using. Typically, its value will be javascript. Although recent versions of HTML (and XHTML, its successor) have phased out the use of this attribute.
  • Type− This attribute is what is now recommended to indicate the scripting language in use and its value should be set to “text/javascript”.

So your JavaScript segment will look like −

<script language=”javascript” type=”text/javascript”> JavaScript code </script>



Leave a Reply