In this article, we introduce you to JavaScript. It is one of the most popular & commonly used languages. Today Javascript powers millions of web pages and makes them interactive. It helps to validate forms, run business logic on the client, create cookies, animate, and much more. It runs on all devices including Windows, Linux, Mac, Android, ios, etc, and supported by all browsers.
Table of Contents
What is Javascript
Javascript is the scripting language, that we use to make web pages interactive. It is written in plain text on the HTML page and runs in the browser. Modern JavaScript evolved so much that, today it can run on the server-side also. We use it along with HTML & CSS and powers the entire web.
History
JavaScript was developed by Brendan Eich of Netscape in 1995. It was started out as Mocha, then became LiveScript and later JavaScript.
Java was a very popular language at that time. Hence the marketing folks at Netscape decided to name it JavaScript so as to encash on the popularity of Java. They also designed it so that its syntax looks similar to that of Java
Microsoft included the support for JavaScript (named as JScript) from the Internet Explorer 3.0. It also included its own scripting language VBScript. JavaScript also incorporated by other browsers, while VBScript remained only with the Internet Explorer. This eventually led to the demise of VBScript.
The browser vendors started to come out with their own implementation of JavaScript. Since there was no standard, each browser was free to implement as they choose to. Hence the need for standardizing the syntax & rules of JavaScript.
In 1997. Netscape presented JavaScript to ECMA International, which standardized the specifications of the JavaScript under the name ECMAScript specifications (pronounced as “ek-ma-script”). The browsers now implement the Javascript using ECMAScript specifications, which is why the JavaScript programs behave similarly across all browsers.
How it is Used
We use JavaScript to create and manage dynamic web pages. It works side by side with HTML & CSS.
The HTML provides the content & structure to the web pages. You can create content using headings, paragraphs, tables & images etc.
The CSS controls how the Web looks like. You can set color, font styles, back grounds, borders etc.
The JavaScript makes it dynamic. Using JavaScript, you can respond to user events, Take input from the user, Validate those inputs, run business logic, read and send data to the servers, etc. It can also alter the content & look by manipulating the HTML & CSS on the fly.
Creating a JavaScript Program
There are two ways you can include JavaScript. You can embed it directly inside an HTML Page or Include it as a separate file.
The following is an example shows how you can write the JavaScript directly in HTML file
1 2 3 4 5 6 7 8 9 10 11 12 13 | <!DOCTYPE HTML> <html> <body> <script> document.write("Hello World from Javascript") </script> </body> <p>The Content from the HTML</p> </html> |
Copy the above code to any text file and name it as index.html
. Open it in any browser and you will see the following in your browser
1 2 3 4 5 6 | Hello World from Javascript The Content from the HTML |
Note that we do not have to do anything to make the above code run. The browser will read the <script>
tag and recognize the content as JavaScript code and executes it.
JavaScript is an interpreted language
JavaScript is an interpreted language. We cannot compile a JavaScript program into an executable. We distribute it as plain text.
To run an interpreted language, the client machines require an Interpreter. The Interpreters reads the program line by line and execute each command. The Interpreted languages were once significantly slower than compiled languages.
Every browser comes with a built in Interpreter in the form of Javascript virtual machine
Javascript virtual machine
The JavaScript virtual machine (JVM) is the component of the browser that reads our JavaScript code, optimizes, and executes it.
The job of JVM is to Interpret the JavaScript code and run it. Each browser comes with a version of JVM. The following is some of the popular JVM
- V8 — Developed by Google for chrome.
- Rhino — Developed ny Mozilla Foundation for Firefox
- SpiderMonkey — The first JavaScript engine, used by Netscape Navigator, and today powers Firefox
- JavaScriptCore — Developed by Apple for Safari
- Chakra — Developed by Microsoft and runs on Microsoft Edge
- JerryScript — is a lightweight engine for the IoT devices
Javascript Tools & Frameworks
There are many tools, Libraries & Frameworks available, which makes working with Javascript easier.
A JavaScript framework is an application framework written in JavaScript. It contains tools & libraries and defines the entire application design.
The following is some of the popular JavaScript libraries & frameworks
Javascript Transpilers
A JavaScript Transpiler is a tool that reads source code written in one another programming language and produces an equivalent code in Javascript.
Very informative blog. Everything in this blog about JavaScript is well explained. Thank you so much this amazing post. Keep posting and keep it up dear.