Introduction to JavaScript
An Introduction to JavaScript
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)\.
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”\.
Different engines have different “codenames”\. For example:
- V8) – in Chrome, Opera and Edge\.
- SpiderMonkey – in Firefox\.
- …There are other codenames like “Chakra” for IE, “JavaScriptCore”, “Nitro” and “SquirrelFish” for Safari, etc\.
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\.
What can in\-browser JavaScript do?
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:
- 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”\)\.