JavaScript is a multi paradigm, dynamic programming language which was created by Brendan Eich in May – 1995 within 10 days of time while he was working for Netscape Communications. It was primarily created to perform small scripting tasks and act as a sidekick for the Java programming language for the browsers, with an aim to make the web more dynamic and provide easier access for developers and designers.
The JavaScript Engine
JavaScript is basically a scripting language that can execute anywhere from browsers to laptops to mobile phones, if a JavaScript Engine is present on that device.
All major browsers like Google Chrome, Firefox, Safari, Edge etc come with their own built-in JavaScript Engine to execute JavaScript code. i.e JavaScript commands can directly be typed into an HTML document, and the web browser will be able to understand them. You do not need to install any additional programs or compilers if you wish to use JavaScript.
JavaScript Engines used by browsers :
– Google Chrome uses the V8 Engine
– Mozilla Firefox uses SpiderMonkey
– Microsoft Edge uses Chakra
– Apple uses JavaScriptCore for its Safari Browser
Besides running on the browser, JavaScript can also execute behind the browser. One particular implementation is Node.js.
Node.js is a JavaScript runtime that makes use of the Chrome`s V8 engine to execute JavaScript on the server and create service-side and networking applications.
This states that you are not just limited to create websites using JavaScript. You can write a full fledged robust system using only JavaScript.
JavaScript In The Web
JavaScript is one of the three layers of web development. The other two are HTML and CSS.
First, Lets take a look at how the three layers fit in together with a basic example.
HTML
First we create a button.
<button id=”btnHello”>Say Hello</button>
CSS
We then add some styles to it.
button {
padding: 10px 20px;
border-radius: 25px;
border: solid 1px green;
}
JavaScript
Finally we add some interactivity to our button.
In this case a simple alert message saying Hello.
const button = document.getElementById(‘btnHello’);
button.addEventListener(‘click’, sayHello);
function sayHello() {
alert(‘Hello’);
}
Here is a simple demo
JavaScript is a versatile language in a sense that it can be used to add any kind of interactivity to a plain website. Things like adding click events to buttons, 2D and 3D animations, displaying image galleries, carousels etc can be all achieved by using JavaScript.
What it can do for you ?
-
Store Information
You can make use of variables, browsers localStorage to store any kind of useful information.
-
Data Manipulation
You can perform many operations from simple addition and multiplications to more complex ones.
-
Use Browser APIs
You can make use of the DOM API to manipulate HTML and CSS, Canvas and WebGL to create animated graphics, Audio and Video API to add multimedia support
-
Use Third Party APIs
You can grab information from third party APIs like Twitter API, Google Maps API and do all kinds of stuffs.
What it can not do ?
-
No Direct Operating System Functionality Access
Unless you are executing JavaScript in the server, JavaScript cannot directly access your computer to do things like reading and writing to a file on your hard drive. Special permissions are required if you wish to access your systems camera and audio devices.
-
Close Other Windows And Tabs
JavaScript cannot close a browsers tab or window that it did not open. This is to avoid cases where a malicious website takes control over your browser and close windows from other websites.
-
Read Information from Opened Web Pages
JavaScript cannot read any kind of information from web pages that came from another server. i.e A Web Page can not just read information from another window that belongs to some other website and find out what else you are doing.
-
No Direct Access To Other Websites
The JavaScript belonging to a web page in one domain cannot access any information about a web page in a different domain. Special permissions can however be configured in the two domains to share resources.