hello friends! new(ish)!

JavaScript

From InstallGentoo Wiki v2
Revision as of 12:11, 2 September 2016 by >Keboler (need a shower, i haven't listed all the es6 features yet)
Jump to navigation Jump to search
"Unofficial" logo.

JavaScript (or ECMAScript) is a scripting language that was originally designed for use in the Netscape web browser, but later became a web standard. JavaScript has traditionally been confined to the browser to add interactivity to web pages, but in recent years has been adopted for use in desktop applications (through technologies such as GJS and Electron) and for server-side use (Node.js, Rhino).

Creator Brendan Eich has been quoted as saying that Javascript "had to ‘look like Java’ only less so, be Java's dumb kid brother or boy-hostage sidekick. Plus, it had to be done in ten days or something worse than JavaScript would have happened."

The language was originally named LiveScript, renamed to JavaScript before release, and is referred to as ECMAScript for the purposes of standardisation.

Criticism

Bloat

Many people hate JavaScript. When it began, it was just a neat sort of thing that allowed pages to be animated. However, later on for a number of reasons, including the rise of Web 2.0, JavaScript became a primary element of RUE websites, causing a page that would otherwise be 1MB long in memory and transmission terms to be 40MB with JavaScript.

The language itself

JavaScript as a language is quite unsound. Possibly as a result of the language originally being written within 10 days, for a very long time JavaScript only had simple function-level scoping, instead of lexical scoping (within blocks) used by almost every other popular programming language (bar the Bourne shell and Emacs Lisp). JavaScript's typing behaviour is clumsy, making many insane coercions between types compared to saner dynamic/duck typed languages such as Python; this problem led to new === and !== equality operators that only allow comparison between two values of the same type. JavaScript also has no standard library; it relies on the often disparate APIs in browsers (or Node), contributing to the cross-browser incompatiblity mess.

ECMAScript 6+

In recent years, there has been a new initiative to add missing features to the language and fix some of it's problems. Previously these efforts were hampered by Microsoft, but in 2015 ECMAScript 6 was finally finished and standardised (but not all of it's features have found their way into browsers yet).

These include:

  • Lexical scoping - ECMAScript 6 introduces two new keywords, let and const to replace var, as such:
let x = 1
{
  x = 2
  console.log(x)
}
console.log(x)
> 2
> 1
  • const uses the same scoping rules as let, but makes that identifier unable to be assigned to another value.

Security

Security risks in JavaScript are extensive, through flaws in the language and exploits in JavaScript runtimes. JavaScript can also be used to make a keylogger.

Software freedom

The method in which JavaScript is executed upon page load without the user's consent is an affront to software freedom - the Javascript Trap. LibreJS is a web plugin designed by the FSF to block non-free JavaScript.