An Introduction to JavaScript
An Introduction to JavaScript
EN
Buy EPUB/PDF
→ The JavaScript language → An introduction
August 8, 2022
An Introduction to JavaScript
Let’s see what’s so special about JavaScript, what we can achieve with it, and what other technologies play well
with it.
What is JavaScript?
JavaScript was initially created to “make web pages alive”.
The programs in this language are called scripts. They can be written right in a web page’s HTML and run
automatically as the page loads.
Scripts are provided and executed as plain text. They don’t need special preparation or compilation to run.
In this aspect, JavaScript is very different from another language called Java.
But as it evolved, JavaScript became a fully independent language with its own specification called
ECMAScript, and now it has no relation to Java at all.
Today, JavaScript can execute not only in the browser, but also on the server, or actually on any device that has
a special program called the JavaScript engine.
The browser has an embedded engine sometimes called a “JavaScript virtual machine”.
The terms above are good to remember because they are used in developer articles on the internet. We’ll use
them too. For instance, if “a feature X is supported by V8”, then it probably works in Chrome, Opera and Edge.
https://javascript.info/intro 1/5
3/9/25, 11:53 AM An Introduction to JavaScript
The engine applies optimizations at each step of the process. It even watches the compiled script as it runs,
analyzes the data that flows through it, and further optimizes the machine code based on that knowledge.
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.
● 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.
● Remember the data on the client-side (“local storage”).
● 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).
https://javascript.info/intro 2/5
3/9/25, 11:53 AM An Introduction to JavaScript
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.
https://javascript.info
https://javascript.info https://gmail.com
<script>
...
</script>
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.
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.
https://javascript.info/intro 3/5
3/9/25, 11:53 AM An Introduction to JavaScript
That’s to be expected, because projects and requirements are different for everyone.
So, recently a plethora of new languages appeared, which are transpiled (converted) to JavaScript before they
run in the browser.
Modern tools make the transpilation very fast and transparent, actually allowing developers to code in another
language and auto-converting it “under the hood”.
● CoffeeScript is “syntactic sugar” for JavaScript. It introduces shorter syntax, allowing us to write clearer and
more precise code. Usually, Ruby devs like it.
● TypeScript is concentrated on adding “strict data typing” to simplify the development and support of complex
systems. It is developed by Microsoft.
● Flow also adds data typing, but in a different way. Developed by Facebook.
● Dart is 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.
● Brython is a Python transpiler to JavaScript that enables the writing of applications in pure Python without
JavaScript.
● Kotlin is a modern, concise and safe programming language that can target the browser or Node.
There are more. Of course, even if we use one of these transpiled languages, we should also know JavaScript to
really understand what we’re doing.
Summary
● JavaScript was initially created as a browser-only language, but it is now used in many other environments as
well.
● Today, JavaScript has a unique position as the most widely-adopted browser language, fully integrated with
HTML/CSS.
● There are many languages that get “transpiled” to JavaScript and provide certain features. It is recommended
to take a look at them, at least briefly, after mastering JavaScript.
https://javascript.info/intro 4/5
3/9/25, 11:53 AM An Introduction to JavaScript
Comments
● If you have suggestions what to improve - please submit a GitHub issue or a pull request instead of
commenting.
● If you can't understand something in the article – please elaborate.
● To insert few words of code, use the <code> tag, for several lines – wrap them in <pre> tag, for
more than 10 lines – use a sandbox (plnkr, jsbin, codepen…)
https://javascript.info/intro 5/5