JavaScript

JavaScript (often shortened to JS) is an Event and Function based programming language created by the Netscape development team on December 4th, 1995.https://web.archive.org/web/20070916144913/http://wp.netscape.com/newsref/pr/newsrelease67.html It is seen as one of three major building blocks of web development, along with HTML and CSS.
== Functionality ==
JavaScript uses curly-bracket and dynamically typed syntax similar to Java. It can be categorized as an "event and function based" programming language. It allows for things such as customs variables (var), strings (" "), basic or complex math, and much more. A basic math problem could be something such as 2 + 2;, but can be more complex in general with combining numbers. Some boolean operations are allowed in addition to the basic functions.
=== Examples ===
==== Alert function example ====
You can make custom alerts on web pages by adding the following code: alert("Hello world!");, which would make Hello world! appear in the alert. The two " " that the text rests in is what defines a string.
==== Custom variables ====
JavaScript allows programmers to add their own variables as well. An up-to-date version of a pre-written code will be presented below, which detects a logged in wiki users username.
;(function (window, $, mw) {
 'use strict';
 var username = mw.config.get('wgUserName');
 if (
 window.disableUsernameReplace ||
 !username
 ) {
 return;
 }
 window.disableUsernameReplace = true;
 var $rail = $('#WikiaRail'),
 customSelector = window.UsernameReplaceSelector
 ? ', ' + window.UsernameReplaceSelector
 : ;
 function inputUsername($content) {
 $content.find('.InputUsername, .insertusername' + customSelector).text(username);
 }
 mw.hook('wikipage.content').add(inputUsername);
 if ($rail.hasClass('loaded')) {
 inputUsername($rail);
 } else if ($rail.length) {
 $rail.on('afterLoad.rail',
 $.proxy(inputUsername, null, $rail)
 );
 }
})(window, jQuery, mediaWiki);
Now another code (Hello, anonymous user!) could be used to present the following text:
:Hello, anonymous user!
==== Advanced ====
The following code can serve multiple functions in JavaScript.
 a.lcm() - b.lcm()) // sort with this comparative function; => is a shorthand form of a function, called "arrow function"
 .forEach(printResult);
function printResult(obj) {
 output(obj + ", gcd = " + obj.gcd() + ", lcm = " + obj.lcm());
}
== References ==
Category:Programming languages
Category:Featured articles