Advantage of Using JavaScript
1. Embedded with in HTML: JavaScript is embedded with in a HTML. It does not require any
separate editor for programs to be written /edited/compiled. Like HTML JavaScript can be
written in simple editor such as HTML.
2. Improved Performance: JavaScript is written with the HTML tags and is interpreted by the
browser. This minimizes storage requirement on the web server and download time for the
client.
3. Minimal Syntax: The rules for the syntax are simple and applications can be quickly
built.
4. Designed for Simple Programs: Simple small programs can be easily written and
implemented using JavaScript. Such programs can be easily integrated in a webpage.
5. An Interpreted Language: JavaScript is an interpreted language. It does not require a
compilation steps. The syntax is interpreted by the browser just as it interprets HTML
tags.
6. Good Programming Constructs: Like other programming languages JavaScript support
facilities like looping, branching, condition checking etc...
7. Designed for Programming Events
8. Easy Debugging: Since JavaScript is an interpreted language easily to debug it line by
line. Also errors are listed as they are encountered.
9. Platform Independence: JavaScript completely independent of the hardware being used. It
just needs a proper installation of browser for its functioning.
10. JavaScript gives HTML designers a programming tool - HTML authors are normally not
programmers, but JavaScript is a scripting language with a very simple syntax! Almost
anyone can put small "snippets" of code into their HTML pages.
11. JavaScript can put dynamic text into an HTML page - A JavaScript statement like this:
document.write("
" + name + "
") can write a variable text into an HTML page.12. JavaScript can react to events - A JavaScript can be set to execute when something
happens, like when a page has finished loading or when a user clicks on an HTML element.
13. JavaScript can read and write HTML elements - A JavaScript can read and change the
content of an HTML element.
14. JavaScript can be used to validate data - A JavaScript can be used to validate form data
before it is submitted to a server. This saves the server from extra processing.
15. JavaScript can be used to detect the visitor's browser - A JavaScript can be used to
detect the visitor's browser, and - depending on the browser - load another page
specifically designed for that browser.
16. JavaScript can be used to create cookies - A JavaScript can be used to store and
retrieve information on the visitor's computer
Similarity with Java and JavaScript
You may get confused between Java and Java Script due to similarity in their names. It is important to understand that Java and JavaScript are two completely different languages both in concept and design. Java is a powerful language developed by Sun Microsystems) as complex as C or C++.
Writing Java script in a webpage
JavaScript syntax is embedded in a HTML file. As browser reads and interprets a HTML file similarly browser uses its in built JavaScript engine to interpret the JavaScript code. Thus all JavaScript code needs to be includes as an integral part of a HTML document. The major question that arises from this discussion is that how browser recognizes a JavaScript code. The browser gets the information about the JavaScript code through the