Page 139 - DCAP408_WEB_PROGRAMMING
P. 139
Unit 5: Scripting Language
Notes
Notes Basic JavaScript is easy to learn, but when you start writing advanced scripts browser
differences (and occasionally syntactic problems) will creep up.
5.1 JavaScript Programming
JavaScript is not the same as Java. Although the names are much alike, JavaScript is primarily a
scripting language for use within HTML pages, while Java is a real programming language that
does quite different things from JavaScript. In addition Java is much harder to learn. It was
developed by Sun for use in pretty much anything that needs some computing power.
Did u know? Who developed JavaScript?
JavaScript was developed by Brendan Eich, then working at Netscape, as a client side
scripting language (even though there’s no fundamental reason why it can’t be used in a
server side environment).
Originally, the language was called Live Script, but when it was about to be released Java had
become immensely popular (and slightly hypey). At the last possible moment Netscape changed
the name of its scripting language to “JavaScript”. This was done purely for marketing reasons.
Worse, Eich was ordered to “make it look like Java”. This has given rise to the idea that JavaScript
is a “dumbed-down” version of Java. Unfortunately there’s not the slightest shred of truth in this
story.
Java and JavaScript both descend from C and C++, but the languages (or rather, their ancestors)
have gone in quite different directions. You can see them as distantly related cousins. Both are
object oriented (though this is less important in JavaScript than in many other languages) and
they share some syntax, but the differences are more important than the similarities.
5.1.1 Advantages of JavaScript
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.
JavaScript can put dynamic text into an HTML page – A JavaScript statement like this:
document. write (“<h1>” + name + “</h1>”) can write a variable text into an HTML page.
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.
JavaScript can read and write HTML elements – A JavaScript can read and change the
content of an HTML element.
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.
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.
JavaScript can be used to create cookies - A JavaScript can be used to store and retrieve
information on the visitor’s computer.
LOVELY PROFESSIONAL UNIVERSITY 133