WWW FAQs: What is JavaScript?

2006-04-19: JavaScript is a simple programming language used to make web pages more interactive. Once known as LiveScript, JavaScript's name was changed as part of a marketing deal between Netscape and Sun. People talk about Java and JavaScript as if they were interchangeable, but they are completely different things. You do not need a Java runtime environment in order to use a JavaScript-enabled web page. See What is Java?

JavaScript code was invented to validate form fields before a form is submitted, saving the user the trouble of waiting to hear back from the web server if the problem is a simple one, like a missing digit in a 10-digit phone number.

Today JavaScript can also be used together with the Document Object Model (DOM) to create powerful web applications like Google's GMail service. GMail lets the user browse through their email without constantly waiting for the web server every time they click. JavaScript is now able to do many jobs that formerly required Java or Flash. Since JavaScript doesn't require plugins, I recommend JavaScript instead of Flash or Java wherever possible, with a fallback plain-HTML option for users with older browsers or handheld devices.

JavaScript code is inserted into a page using the <script> element, like this:

alert("This displays a message box to the user");

JavaScript code also appears in "event handlers," special attributes of other HTML elements that trigger JavaScript code. One example of an event: when the mouse moves over an image, any JavaScript code provided in an onMouseOver attribute is executed.

To learn more, see the w3schools JavaScript tutorial.

Legal Note: yes, you may use sample HTML, Javascript, PHP and other code presented above in your own projects. You may not reproduce large portions of the text of the article without our express permission.

Got a LiveJournal account? Keep up with the latest articles in this FAQ by adding our syndicated feed to your friends list!