Introduction to JavaScript

JavaScript is a programming language for the web. It is lightweight and dynamic and weakly typed.
JavaScript is an essential part of web applications because it enables interactivity in websites and web applications.


JavaScript was developed by Netscape as a glue language for HTML. Earlier, it was named "LiveScript". Later renamed to JavaScript. Microsoft also releases JScript and VBScript. So it was very difficult for programmers and designers to make their site work in two major browsers. So the websites were of two types: Best viewed in Netscape and Best viewed in Internet Explorer.

What is ECMAScript?

ECMA International came into the picture to solve this browser wars and make the JavaScript standard. The last draft of ECMA Internation is known as ECMAScript 2017

Program in JavaScript

Program in JavaScript is known as script. Script directly can be embedded into HTML or external javascript file can be loaded into the webpage.

JavaScript doesn't need to be compiled. It directly runs as plain text into the HTML page as it loads.

JavaScript files have .js extension.

What JavaScript can do?

JavaScript which runs in the browser, ( from now on, we will call it Client Side JavaScript) can do almost everything related to the webpage.

  • Interaction with DOM

    JavaScript can dynamically add, remove and change the elements of the webpage.

  • Interactivity in webpage

    JavaScript can react to the user's action. Using JavaScript, you can add do certain things when the user does some interactivity on the webpage. i.e When the user clicks the button, you can show some text on the webpage.

  • Interact with server

    Using JavaScript, you can send the request to the server to send some data and get the response. Or you can get some data from the server.
    i.e. When the user fills his/her information in the login form, you can send data ( username and password ) to the server and get the verification in response.

  • Cookies Management

    You can add, delete and change the cookies using JavaScript.

What JavaScript cannot do?

There are few things which JavaScript cannot do for the safety of user's data.

  • Access the files in a hard disk

    JavaScript cannot access files inside the hard disk. JavaScript can access only Files which is dropped by the user inside webpage or selected using input tag.

  • Access the microphone and camera

    JavaScript cannot access microphone and camera directly without the permission from the user. While accessing the microphone or camera, if user permits, then and only then JavaScript can access them.

  • Interact with another server

    JavaScript can easily communicate with the server from which webpage is a server. But it cannot send a request to other servers. Although, it is possible if the other server provides permission in its response header. It is called Cross-origin resource sharing.

  • Interacting with other tabs and windows

    Generally, One window or tab opened in the browser doesn't know about the other window or tabs ( Unless one window is opened by another window). If one tab wants to exchange data, both pages must incorporate particular JavaScript code. For more info please visit this link.

Server-side JavaScript

After releasing JavaScript for browsers, Netscape also introduced server-side scripting which runs in Netscape Enterprise Server.

Microsoft's IIS also supported server-side JScript for ASP and .NET pages.

In 2009, Node.js was introduced. Node.js provides an environment to run the JavaScript on the server side. So JavaScript can run anywhere where Node.js is installed beside browser.

We will add a course on Node.js in near future.

JavaScript Wrappers

JavaScript is dynamic, weakly typed scripting language. Since it is weakly typed, It is little hard to develop very big project only in JavaScript and the intellisense provided by the editors are very less.
In a large project, there will be countless modules and each module will use other module's function. Now due to weakly type, a function taking an integer as a parameter will also take a string as a parameter. This won't be encountered in intellisense. You will get the error when you run the program. So large projects are little hard to develop in JavaScript.
To Solve this problem there are wrappers written around JavaScript. These wrappers are written in a different script but the will be compiled into JavaScript.

  • CoffeeScript

    An alternate syntax for JavaScript intended to be more concise and readable. It adds syntactic sugar inspired by Ruby, Python, and Haskell in an effort to enhance JavaScript's brevity and readability. For more info, please visit this link.

  • TypeScript

    A free and open-source programming language developed by Microsoft. It is a superset of JavaScript, and essentially adds support for optional type annotations and some other language extensions such as classes, interfaces, and modules.


So, in this section, you learned about JavaScript, its history, what it can do and what it cannot do.
In next section you will learn about tools that can be used to develop project in JavaScript.