It all started with Java. Java, developed by Sun Microsystems was intended to be used only in consumer electronics, but now itâ€™s used as an advanced programming language for the Internet. First browser to implement Java was HotJava, developed by Sun Microsystems for testing purposes. Netscape integrated it in its browser, Navigator, and after this Java gained interest.
Webpages visually enhanced, functionality increased, CGI scripts used more rarely, and all that with a programming language that is a lot easier to learn and makes programming simple things a lot easier.
Java is a high-level programming language used by advanced programmers, developed by Sun. Java code must be compiled before it can be used.
Things to know about JS
After significant modifications were added by Microsoft and Netscape to their Java scripting language version, new versions are developed, and handed to ECMA Organization that makes one standard scripting language out of them, called ECMAScript.
JS is Client-Side
There are two types of programming languages on the Internet, Server-side and Client-side.
Server-side languages are exclusive for servers, and use server resources; the result is being displayed on the client computer (the computer thatâ€™s accessing the webpage). A server-side language often used is PHP.
Basically, there are two types of programming languages:
Compiled languages require that after you write the code, to transform it in machine language (pure code that itâ€™s very easy and fast to understand by the computer). Machine code is usually binary code. Every time you run the code (for testing), you must compile it with a compiler. After your application is finished, you can do a full compile and it will result an executable file (exe for example). There are advantages and disadvantages. Compiled languages run faster than interpreted language, are more stable, offer more control, the code is easier to protectâ€¦ the only disadvantage is that when you develop your application and test it, you must compile it to run it, but itâ€™s not a big problem, usually this doesnâ€™t take more than a matter of seconds. All executable applications that you use, like MS Word, Outlook Express, Macromedia Dreamweaverâ€¦ are compiled.
Object-Oriented based language
Source code not protected
Because itâ€™s not a compiled language, and it runs on client-side, your JS code is available to see by all your visitors, and steal it. The only way you can make it harder to be copied is to write your code in a separate file. Doing so doesnâ€™t fully protect your code, and if the visitor really wants to see your code, he will. But more about this in the next chapters.
JS extends HTML
Event-driven languages are those that need an event to trigger an action. For example, in a dialog box, to continue, or to stop, you must click OK or Cancel, respectively. If you click OK, the program will start and continue its work. If you click Cancel, it will exit. To start working or to exit are actions driven by the button you choose. If you donâ€™t click anything, the program will do nothing. This is how an event-driven language acts.
What is it good for?
Text validation was inconvenient with good old CGI, and itâ€™s still the same with PHP and other server-side languages. Letâ€™s think at a formâ€¦ just like the ones you see every day on the internet where they ask you to register or to login somewhere. If you misspell something, you donâ€™t enter you ZIP Code in the correct format for example, the form will be sent to the server, you wait while the page loads (if the server is busy, you will waitâ€¦). Then the server processes the form, it sees that you didnâ€™t complete it correctly, and sends you a page where you find out what misspell you have done, and that you must go back to correct it.
You can put current time on different places on earth if you have a news site or an advanced calculator if you have a science site, or one that works based on a formula.
If you know that your webpage doesnâ€™t work well with a specific browser, you can make a script that will detect the browser and warn the user that the webpage isnâ€™t designed for that browser, or for that screen resolution, or color depth. You can also find this kind of information about your visitors, including their IP address and who referred them to your webpage.
You can store cookies on the clientâ€™s computer, and when they visit the site again the script will know itâ€™s the same visitor. This helps you a lot. Itâ€™s especially used at login systems. If the visitor is registered on the site, the next time he will visit the site, it will be logged in.
Compatibility is an important thing, which a webmaster and programmer should pay attention to, though nowadays browsers tend to keep up with the newest versions, and compatibility doesnâ€™t represent such a big problem no more.
JS and the browsers
This information is useful because you will probably want that your script to work with older browsers, that are still used. Of course, you wonâ€™t do scripts that work with Netscape Navigator 2, because probably no one is using this browser anymore. But you will try to make your scripts compatible with Internet Explorer 5.5, because there may be some users who use this older version of Internet Explorer, though there are no extreme differences between version 1.4 and 1.5 of JS, and definitely you wonâ€™t use the new function implemented in version 1.5 in all your scripts.
Siteâ€™s target visitors matters
You can make your scripts compatible depending on your target visitors. For example if you make a site for webdesigners, it shouldnâ€™t be such important to make your script compatible with Internet Explorer 5 or Netscape 4, because you siteâ€™s target are webdevelopers, who work with this kind of web technologies, and they probably use the latest versions of the browsers.
On the other hand, if you make a script for a banner-exchange system, you never know on what site the script ends-up, maybe on a culinary site, where the user probably doesnâ€™t have big knowledge about computers, so he doesnâ€™t keep his computer updated.
A browser can interpret a piece of JS code different from another, but this is the happy case, when it doesnâ€™t give an error. Some browsers actually donâ€™t do anything when they can handle a piece of code; others throw an unpleasant error, or display something strange. Itâ€™s better to test your script with the most used browsers, to see if your script works fine with them.