Introduction To JavaScript

What Is JavaScript?

JavaScript is a very powerful client-side scripting language. JavaScript is used mainly for enhancing the interaction of a user with the webpage. In other words, you can make your webpage more lively and interactive, with the help of JavaScript. JavaScript is also being used widely in game development and Mobile application development.


JavaScript was developed by Brendan Eich in 1995, which appeared in Netscape, a popular browser of that time.

The language was initially called LiveScript and was later renamed JavaScript. There are many programmers who think that JavaScript and Java are the same. In fact, JavaScript and Java are very much unrelated. Java is a very complex programming language whereas JavaScript is only a scripting language. The syntax of JavaScript is mostly influenced by the programming language C.

Being a scripting language, JavaScript cannot run on its own. In fact, the browser is responsible for running JavaScript code. When a user requests an HTML page with JavaScript in it, the script is sent to the browser and it is up to the browser to execute it.

Uses Of Javascript

1. Web Development

JavaScript is a client scripting language which is used for creating web pages. It is a standalone language developed in Netscape. It is used when a webpage is to be made dynamic and add special effects on pages like rollover, roll out and many types of graphics. It is mostly used by all websites for the purpose of validation.

In addition to validations, it supports external applications like PDF documents, running widgets, supporting for flash applications etc. It can also load content into a document whenever the user requires it without even reloading the entire page.

2. Web Applications

With technology browsers and personal computers have improved to an extent that a language was required to create robust web applications. When a user explores a map in Google Maps then the user just needs to click and drag the mouse. All detailed view is visible by just a click.

This is possible due to JavaScript. It interacts with the browser without sending messages to and fro to the servers. JavaScript uses Application Programming Interfaces(APIs) that provide extra powers to the code.

3. Presentations

JavaScript also provides the facility of creating presentations as a website. JavaScript provides RevealJS and BespokeJS libraries to build a web-based slide deck. Reveal.js creates some of the most beautiful and interactive decks using HTML. A user can easily insert nested slides.

Even if the user is not aware of programming language then they can easily build a site with so much help online. These presentations are touch optimized and work great with mobile devices, phones, and tablets. With all this JavaScript also provides different transition styles, themes, and slide backgrounds. It supports all CSS color formats. 

JavaScript also provides Bespoke.js plugin with a wide variety of features. These include responsive scaling, animated bullet lists, and syntax highlighting for code examples.

4. Games

Not only websites but uses of JavaScript also helps in creating games for leisure. The combination of JavaScript and HTML5 makes JavaScript popular in games development as well. It provides the Ease JS library which provides simple solutions for working with rich graphics.

It also has an API that is familiar to all flash developers with a hierarchical display list. A user can create a Stage and it will render the display list to its target canvas. Ease JS also has 2D bitmaps called Sprites which are drawn directly to render the target for transformations.

5. Smartwatch Applications'

Javascript being the most used language is because it is being used in all possible devices and applications. uses of JavaScript provides a library Pebble JS which is used in smartwatch applications. This framework works for applications that require the internet for its functioning. Using Pebbles allows a developer to create an application for a number of watches using JavaScript.

How To Run JavaScript?

The main advantage of JavaScript is that all modern web browsers support JavaScript. So, you do not have to worry about whether your site visitor uses Internet Explorer, Google Chrome, Firefox or any other browser. JavaScript will be supported.

Also, JavaScript runs on any operating system including Windows, Linux or Mac. Thus, JavaScript overcomes the main disadvantages of VBScript (Now deprecated) which is limited to just IE and Windows.

Tools You Need

To start with, you need a text editor to write your code and a browser to display the web pages you develop. You can use a text editor of your choice including Notepad++, Visual Studio Code, Sublime Text, Atom or any other text editor you are comfortable with. You can use any web browser including Google Chrome, Firefox, Microsoft Edge, Internet Explorer etc.

A Simple JavaScript Program

You should place all your JavaScript code within <script> tags (<script> and </script>) if you are keeping your JavaScript code within the HTML document itself. This helps your browser distinguish your JavaScript code from the rest of the code.

As there are other client-side scripting languages (Example: VBScript), it is highly recommended that you specify the scripting language you use.  You have to use the type attribute within the <script> tag and set its value to text/javascript like this:

<script type="text/javascript">
	<title>My First JavaScript code!!!</title>
	<script type="text/javascript">
		alert("Hello World!");

What Can and Can't in-browser JavaScript Do?

In-browser JavaScript can do everything related to webpage manipulation, interaction with the user, and the webserver. However, JavaScript’s abilities in the browser are limited for the sake of the user’s safety. The aim is to prevent an evil webpage from accessing private information or harming the user’s data.

For instance, in-browser JavaScript is able to:

  • Add new HTML to the page, change the existing content, modify styles.
  • React to user actions, run on mouse clicks, pointer movements, key presses.
  • Send requests over the network to remote servers, download and upload files (so-called AJAX and COMET technologies).
  • Get and set cookies, ask questions to the visitor, show messages.

Examples of such restrictions include:

1. JavaScript on a webpage may not read/write arbitrary files on the hard disk, copy them or execute programs.

It has no direct access to OS system functions. Modern browsers allow it to work with files, but the access is limited and only provided if the user does certain actions, like “dropping” a file into a browser window or selecting it via an <input> tag.

There are ways to interact with camera/microphone and other devices, but they require a user’s explicit permission.

So a JavaScript-enabled page may not sneakily enable a web-camera, observe the surroundings and send the information to the NSA.

2. JavaScript from one page may not access the other if they come from different sites.

Different tabs/windows generally do not know about each other. This is called the “Same Origin Policy”. To work around that, both pages must agree for data exchange and contain a special JavaScript code that handles 

Languages “over” JavaScript

  1. CoffeeScript
    A “syntactic sugar” for JavaScript. It introduces shorter syntax, allowing us to write clearer and more precise code. Usually, Ruby devs like it.
  2. TypeScript
    Concentrated on adding “strict data typing” to simplify the development and support of complex systems. It is developed by Microsoft.
  3. Flow
    Also adds data typing, but in a different way. Developed by Facebook.
  4. Dart A standalone language that has its own engine that runs in non-browser environments (like mobile apps), but also can be transpiled to JavaScript. Developed by Google.

Share this article