The internet houses millions of web pages hosted by websites that serve different purposes. Some attract you while others don’t. You like the ones which look good, are easy to use, and interactive enough to engage you for long. This is where Javascript comes into the scene. What is it used for? Let’s find out.
Most web pages are made in HTML. It is a very simple language that lets you add various elements to a web page, making it attractive and enhancing its readability. It allows the use of embedded images, colors, and basic animation on web pages, thus enhancing their look and feel. The use of CSS (Cascading Style Sheets), provides greater flexibility and reduces the overall code complexity of web pages. Thus, it becomes easier to present the page content in different devices such as cell phones, tablets, and desktop computers. What is JavaScript used for then? Well, it’s mainly used to add interactive elements to web pages, which makes them more user-friendly and appealing. HTML pages of the modern times use Javascript. Let’s get down to show you what it can do and how it is used.
JavaScript is a programming language usually run on the client side. It is used to interact with the user. It is also used in the development of games as well as desktop and mobile applications. It is used in the creation of PDF documents and desktop widgets. Web browsers have an in-built support for it.
■ One of the earlier uses of JavaScript was in the dialog box messages that provided warnings, alerts, or prompts to the users.
■ The content of HTML elements can be changed with the help of Javascript. This needs the use of HTML DOM, wherein HTML elements are defined as objects.
■ Javascript can be used to accept user feedback through online forms.
■ It is widely used in sign-up forms to accept an individual’s username and password.
■ A search box that accepts user inputs, based on which search results are rendered, makes use of Javascript.
■ It is of use in fixing the arrangement of elements on a page and deciding to load them selectively. Thus, it is of help in creating better page layouts.
■ JavaScript supports HTML, and can be used to enhance web pages in many ways. It can be used to add several such elements to web pages that simple HTML cannot. The use of audio, animation, and video, is made easier with the use of Javascript.
■ It can be used to hide information and disclose it on user action. For example, clicking on the ‘read more’ button discloses information which was hidden on page load, or clicking on a ‘Yes’ or ‘No’ button leads you to a page/section you weren’t shown by default.
■ Javascript can be used to accept user comments or customer feedback online. This is usually in the form of text boxes that appear on user action and prompt the user to provide text-based inputs, which are received and displayed or stored for further use.
■ It can be used to store IP addresses of visitors and record their page visits.
■ Javascript is easy to implement. It allows for the creation of responsive interfaces. It can load content on user action, thus eliminating the need to load the entire page content when the user is going to use only a part of it.
■ It can be used to test browser actions and fix browser issues.
■ Extensions of browsers like Chrome, Opera, and Safari 5 are implemented using Javascript.
■ The MongoDB database accepts queries in Javascript.
■ Adobe’s Acrobat and Adobe Reader support Javascript in PDF. Adobe’s creative suit allows its use for scripting.
■ OpenOffice.org allows the use of Javascript as a scripting language.
■ Google Apps script (a cloud-based scripting language that allows users to automate tasks, create custom formulas, and interact with Google products) is based on Javascript.
■ Java has introduced the javax.script package to allow for the implementation of Javascript, thus enabling Java applications to host scripts. The Qt C++ toolkit includes QtScript to interpret Javascript.
■ Javascript comes with certain security risks. But with the use of its subsets such as ADsafe and Secure ECMAScript (SES), greater security can be provided.
Example 1
The first example is a simple one and commonly seen in menu items. If you move your mouse over some link or menu button, it changes color. This change of color on user action, can be used to give different visual effects and also enhance the look of a web page. In the example below, take your mouse over the button of your choice and see it change to the respective color.
Red
Green
Blue
Example 2
This is a perfect example of an event. We come across something similar on several web pages. On the event of clicking a button, a message is displayed. It may tell you what to do next or inform you of something useful. In the example below, a simple message is displayed on clicking the button.
Button
Although JavaScript is used extensively, the user shouldn’t completely depend on it. It has certain security issues as anyone can duplicate the code. Different browsers interpret it differently according to their rendering engines, which may lead to inconsistencies in the display. However, despite concerns like these, Javascript is popular and widely used across the web.