473,408 Members | 1,623 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ


What is Javascript?

By Jillian Carroll
Administrator, TheScripts.com

What is Javascript?

JavaScript need not be a scary thing to approach. It can bring a deeper level of interactivity and functionality to otherwise bland HTML, and has a fully developed standard for web-developers to follow. This means you do not have the same cross-browser compatibility issues that often creep out from under the carpet of DHTML.

JavaScript is an easier to understand, less complex version of its distant cousin, Java. Developed by Netscape, it carries with it a smaller command set and a much simpler structure, though it remains an OOP (Object Oriented Programming Language). OOP can make a language easier to tackle, by breaking a program up into 'parts' to make up the whole. The easiest way to explain this may be with an example. You can look at an OOP as if you were building a desk instead of a program: the parts may be the legs, the top, perhaps a hutch and a set of drawers. Without the legs, it is just a slab of wood and put them together and you have something to put a glass of water on. If you want to get fancy, add the hutch -- which would look silly without the rest of the desk! The important thing to remember is that you must not use any part of the legs to build that hutch, and you cannot cut up the slab you are using for the top and use it to make the drawers.

Something important to note is that JavaScript is unable to stand on its own like Java. It is a text-based language that must be placed within HTML, to be read by the browser and interpreted so the instructions can be performed. Because of this, JavaScript is also very easy to edit: simply alter the text, and re-run the HTML. For simple applications, this is ideal; for complex applications, this is limiting. When writing in Java, the HTML document generally does little other than 'call upon' the applet (Java application). JavaScript is geared entirely towards web-development while Java, because of its amazing versatility, is geared to almost any use you have in mind.

With all of that said, the following script is a great example of what you may use JavaScript for.

Preloading (Caching) Images

<SCRIPT LANGUAGE="JavaScript">
<!-- hide from non-JavaScript Browsers
  Image1= new Image(100,100)
  Image1.src = "graphic1.gif"
  Image2 = new Image(35,90)
  Image2.src = "graphic2.gif"
  Image3 = new Image(115,89)
  Image3.src = "graphic3.gif"
// End Hiding -->
</SCRIPT>

To use this script:

1. Place the script between the <head></head> tags in your document (you do this with many JavaScripts, so they will be loaded before the HTML below them). Replace graphic1.gif, graphic2.gif and graphic3.gif with the filenames ofthe images you wish to preload (add or subtract to these 3, as your document requires). Your images do not need to be .gif, you may use .jpg or any other acceptable Internet graphic format.

2. Replace the (x,y) coordinates with the height and width of your images.

It is from this basic script that the famous 'on_mouseover' is derived.

 

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.