In the mid-90s, after the advent of thw World Wide Web, a program was needed to make web pages come "alive". This task was taken up by Brendan Eich, who developed it for Netscape 2. This language uses programs known as scripts which can be written in an HTML file and run automatically as the page loads. Scripts are created and executed as plain text, hence they do not require any special compilation to run.
He named it JAVASCRIPT
JavaScript can be run in the browser, in servers, or on any device that has a "JavaScript engine".
Different engines have different “codenames”. e.g V8 in Chrome and SpiderMonkey in Firefox
Modern JavaScript is a “safe” programming language. It does not provide low-level access to memory or the CPU, because it was initially created for browsers which do not require it.
JavaScript’s capabilities greatly depend on the environment it’s running in. For instance, Node.js supports functions that allow JavaScript to read/write arbitrary files, perform network requests, etc.
In-browser JavaScript can do everything related to webpage manipulation, interaction with the user, and the webserver.
For instance, in-browser JavaScript is able to:
JavaScript’s abilities in the browser are limited to protect the user’s safety. The aim is to prevent an evil webpage from accessing private information or harming the user’s data.
Examples of such restrictions include:
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 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 the 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.
Different tabs/windows generally do not know about each other. Sometimes they do, for example when one window uses JavaScript to open the other one. But even in this case, JavaScript from one page may not access the other page if they come from different sites (from a different domain, protocol or port).
This is called the “Same Origin Policy”. To work around that, both pages must agree for data exchange and must contain special JavaScript code that handles it. We’ll cover that in the tutorial.
This limitation is, again, for the user’s safety. A page from
http://anysite.com which a user has opened must not be able to
access another browser tab with the URL http://gmail.com, for
example, and steal information from there.
JavaScript can easily communicate over the net to the server where the current page came from. But its ability to receive data from other sites/domains is crippled. Though possible, it requires explicit agreement (expressed in HTTP headers) from the remote side. Once again, that’s a safety limitation.
Such limitations do not exist if JavaScript is used outside of the browser, for example on a server. Modern browsers also allow plugins/extensions which may ask for extended permissions.
There are at least three great things about JavaScript:
JavaScript is the only browser technology that combines these three things.
That’s what makes JavaScript unique. That’s why it’s the most widespread tool for creating browser interfaces.
That said, JavaScript can be used to create servers, mobile applications, etc.
A Full Stack Developer. I specialize in Laravel, Node, and Frontend Javascript frameworks.