# An introduction to JavaScript Let's see what's so special about JavaScript, what we can achieve with it and what other technologies coexist with it. ## What is JavaScript? *JavaScript* was initially created to *"make webpages alive"*. The programs in this language are called *scripts*. They are put directly into HTML and execute automatically as it loads. Scripts are provided and executed a plain text. They don't need a special preparation or compilation to run. In this aspect, JavaScript is very different from another language called [Java](http://en.wikipedia.org/wiki/Java). [smart header="Why JavaScript?"] When JavaScript was created, it initially had another name: "LiveScript". But Java language was very popular at that time, so it was decided that positioning a new language as a "younger brother" of Java would help. But as it evolved, JavaScript became a fully independent language, with its own specification called [ECMAScript](http://en.wikipedia.org/wiki/ECMAScript), and now it has no relation to Java altogether. It has quite a few special features that make mastering a bit hard at first, but we'll nicely deal with them later. [/smart] Since the time of its creation, JavaScript evolved. As of now, JavaScript can execute not only in the browser, but also on the server, or actually on any device where a special program called [an interpreter]("http://en.wikipedia.org/wiki/Interpreter_(computing)") is installed. The execution process is called "an interpretation". The browser has an embedded JavaScript interpreter, of course. Sometimes it's also called a *JavaScript engine* or a "JavaScript virtual machine". Different engines have different "codenames", for example: The codenames are usually used when searching for detailed information in the internet. Also, we'll use them further to be more exact. Instead of the words "Chrome supports feature..." we'd rather say "V8 supports feature...", not just because it's more precise, but because that also implies Opera and Node.JS. [smart header="Compilation and interpretation"] There are in fact two general approaches to execute programs: "compilers" and "interpreters". Modern interpreters actually combine these approaches into one: the script is distributed as a plain text, but prior to execution is converted to the machine language. That's why JavaScript executes very fast. [/smart] ## What in-browser JavaScript can do? The modern JavaScript is a "safe" programming language. It does not provide low-level access to memory or CPU, because it was initially created for browsers which do not require it. Other capabilities depend on the environment which runs JavaScript. For instance, Node.JS has functionality that allows JavaScript to read/write arbitrary files, perform network requests etc etc. In the browser JavaScript can do everything related to webpage manipulation, interaction with the user and the webserver. In more details, in-browser JavaScript is able to: ## What in-browser JavaScript can NOT do? JavaScript abilities in the browser are limited. That is for user safety, mainly not to let an evil webpage access private information or harm the user's data. Such limits do not exist if JavaScript is used outside of the browser, for example on a server. Modern browsers also allow installing plugin/extensions which get extended permissions. ## Why JavaScript is unique? There are at least *three* great things about JavaScript: [compare] +Full integration with HTML/CSS. +Simple things done simply. +Supported by all major browsers and enabled by default. [/compare] Combined, these 3 things only exist in JavaScript and no other browser technology. That's what makes JavaScript unique. That's why it is the most widespread way of creating browser interfaces. Of course, there are certain trends including new languages and browser abilities. While planning to learn a new technology, it's beneficial to check it's perspectives, so we go ahead with that. ## HTML 5 *HTML 5* is an evolution of HTML which adds new tags and what's more important -- new browser abilities, accessable from JavaScript. Few examples: Many new abilities are still in progress, but browsers gradually improve the support for them. [summary] The trend: browser can do more and more, it is becoming more like an all-purpose desktop application. [/summary] Still, there is a small gotcha with those "extra-fresh" modern browser abilities. Sometimes browsers try to implement them on very early stages when they are nor fully defined neither agreed upon, but still are so interesting that the developers just can't wait. ...As the time goes, the specification matures and changes, and browsers must adapt it. That may lead to errors in the older code which was too eager to use the early browser implementation. So one should think twice before relying on things that are in draft yet. But what's great -- eventually all browsers tend to follow the standard. There are much less differences between them now than only a couple years ago. [summary] The trend: browsers, though eager for new features, tend to be compatible with the standard. [/summary] ## New EcmaScript JavaScript evolves. The upcoming EcmaScript-2016 standard adds more language-level features which make the syntax more capable and expressive. Modern browsers improve their engines to raise JavaScript execution script, fix bugs and try to follow the standards. [summary] The trend: JavaScript is becoming faster, gets new syntax and language features. [/summary] ## Languages "over" JavaScript The syntax of JavaScript does not suit everyone's needs: some people think that it's too flexible, the others consider it too limited, the third ones want to add new features absent in the standard... That's normal, because projects and requirements are different for everyone. There's no a single standard for a carpenter's hammer, why should it exist for the language? So recently a plethora of new languages appeared, which are *transpiled* (converted) to JavaScript before they run. The transpilation happens automatically, modern tools make the process very fast and transparent, actually allowing developers to code in another language. But they still should know JavaScript, to better understand what they are doing. Examples of such languages: ## Summary