JavaScript programming language: structure, capabilities, learning

JavaScript, for short, JS is an interpreted programming language, so it does not need to be compiled. It came from Java and is mainly used for creating web pages. JS was designed with syntax similar to C, although it accepts the names and conventions of the Java programming language. However, Java and JS have different semantics and goals, which affects how JavaScript works. It is mainly used in client-side form, implemented as part of a web browser, which improves the user interface and dynamic web pages. There is a form of server-side JavaScript or SSJS that is used in applications external to the Internet, such as PDF documents and widgets.

JavaScript History

JavaScript History

Multi-paradigm programming language JS. It was developed by the Americans back in the 1990s. Its founder is Brendan Ike from Netscape with the original name Mocha, later it was renamed LiveScript, and only then in JavaScript. This change coincided with the time when Netscape in December 1995 added support for Java technology in its Netscape Navigator web browser in version 2.002. The name caused confusion, giving the impression that the language is an extension of Java and has been described by many as the Netscape marketing strategy to gain prestige and innovation in new web programming languages.

JavaScript is a registered trademark of Oracle Corporation. It is used with a license for products created by Netscape Communications and current organizations such as the Mozilla Foundation, under the direction of Brendan Ike. Microsoft created its JS dialect JScript as a name to avoid brand-related issues. JScript was adopted in Internet Explorer version 3.0, released in August 1996, and included compatibility with Effect 2000. The dialects seem so similar that the terms JavaScript and JScript are often used interchangeably, but the JScript specification is in many ways incompatible with ECMA.

Official specifications

In 1997, the authors proposed the adoption of the JavaScript programming language as the standard of the European Computer Manufacturers Association ECMA. In June 1997, it was adopted under the name ECMAScript, and shortly thereafter, also in the form of ISO / IEC-16262.

The language specification that controls JavaScript is called ECMAScript. The Ecma International structure that reviews and accepts changes is called Technical Committee 39 or TC39. ECMA has published several standards related to ECMAScript. The first edition came out in June 1997. A year later, minor changes were made to adapt it to ISO / IEC-16262, and a second edition was created. The third standard was published in December 1999, in the version used in modern browsers. The fourth variation of ECMA-262 was not released, the fifth came in 2009, then was reissued in 2011. The sixth was released in 2015, and then the update took place annually. The latest version 9 was released in 2018.

Candidates for ECMAScript 2019

Candidates for ECMAScript 2019 are already ready, TC39 proposals are at stage 4, its release is expected in June this year. You can try the new product today, some functions are interspersed with JavaScript in utilities. If they are disabled by default, then you can easily launch them in your browser settings. More detailed standards are described in books on JavaScript, which can be downloaded free of charge on the Internet on specialized sites.

Server side js

Netscape introduced a server-side scripting implementation for Netscape Enterprise Server in December 1994, shortly after the release of JavaScript for web browsers. Since the mid-2000s, there have been many JS implementations on the server side. Node.js is one of the striking examples that is used in important projects.

The JavaScript programming language has become one of the most popular languages ​​on the Internet. At first, many developers rejected it. The advent of Ajax brought JS back to fame and attracted the attention of other developers. As a result, there has been an increase in the set of frameworks and general purpose libraries. This allowed us to improve programming methods using the language and expand the use of JS outside of web browsers, which is evident from the spread of the JavaScript structure on the server side.

Imperative and structured

JavaScript is compatible with most of the C programming framework, such as using if statements, for loops, switch statements, and others. JavaScript 1.7 added support for determining block size using the let keyword. As in C, JS distinguishes between expressions and sentences. The syntactic difference with respect to C is the automatic insertion of semicolons, that is, in JS those that end sentences can be omitted.

As with most scripting languages, a type is associated with a value, not a variable. The JavaScript programming language supports several methods for checking the type of an object. One of them is to find out through the typeofObjetual keyword.

JS almost entirely consists of objects - associative arrays, improved through the use of prototypes. Properties and their values ​​can be created, changed / deleted at runtime. Most of them are included in the inheritance chain and are listed using the for ... in loop statement. JS has a small number of predefined objects, such as Functiony Date.

First class functions

JavaScript includes an eval function that allows you to evaluate expressions as strings at runtime. It is recommended to use it carefully, it is better to use the JSON.parse () function as often as possible, because it is much safer, and programming lessons from scratch will help you to better understand this.

First-class functions have properties and methods, such as .call () and .bind (). A nested function is one that is defined in another that is created whenever an external function is called. In addition, each forms a closure, which is the result of evaluating a domain containing one or more dependent variables from another external environment, including constants, local variables, and arguments to the calling function. The result of evaluating the indicated closure is part of the internal state of the object, even after the external function completes its actions.

Prototypes instead of classes

Prototypes instead of classes

JS uses prototypes instead of classes to use inheritance. You can emulate many of the functions provided by classes in object-oriented languages ​​through prototypes.

Functions also behave like constructors. The call prefix with the new keyword creates a new prototype instance that inherits properties and methods from the constructor, including Object properties. ECMAScript 5 offers an Object.create method that allows you to instantiate without the need for automatic inheritance from Object. In earlier environments, a prototype created as null can be formed. The prototype property of the constructor defines the object for the internal newly created prototype. New methods can be added by changing the prototype of the object, as a constructor.

Runtime

Runtime

The JavaScript programming language usually depends on the runtime, for example, in a web browser, to offer objects and methods by which scripts can interact with the "outside world". In fact, it depends on the environment that enables the inclusion or import of scripts, for example, in HTML using a tag. This is not a language feature, but it is common in most JS implementations.

An undefined number of parameters can be passed to it. She gets access to them through parameters or a local arguments object. The variádicas function can be created using the .apply () method. Unlike many object-oriented languages, there is no difference between the definition of a function and a method. Rather, it occurs during a function call that can be executed as a method with the this keyword, a local variable for the object that called the function.

As in many scripting languages, arrays and objects can be created with a shorthand syntax, so the developer will always need a handy JavaScript programming language handbook. In fact, these literals form the basis of the JSON data format. JavaScript also supports regular expressions, like Perl, which provides a concise and powerful syntax for processing text that is more complex than functions built into string objects.

Differences: Java & JavaScript

Differences: Java & JavaScript

JS language is very different from Java, JavaScript has much more features. Although it is an object-oriented programming language, it has no inheritance, unlike Java, so JS is an event-oriented language.

Another difference between the two languages ​​is that although Java can create stand-alone applications, such as applets, programs that include in web pages, JavaScript is embedded in the web, forming part of the HTML code without which it cannot exist.

These two languages ​​have a large common part of the syntax, structure, establish a hierarchy of objects to determine their properties, and other elements that have much in common with C and C ++.

You can include JavaScript code in any web page or HTML, like a server in PHP documents. This code is included in HTML tags, for example, </ SCRIPT>. JS distinguishes between uppercase and lowercase letters and is mainly used to create dynamic web pages.

Including language in XHTML documents

JavaScript and XHTML integration is very flexible, there are at least three ways to include code in web pages.

Including language in XHTML documents

Action algorithm:

  1. JavaScript code is wrapped between labels and added to any part of the document. It is recommended that you define the code in the document title.
  2. For the resulting XHTML page to be valid, you must add the type attribute to the tag. The values ​​included in it are standardized, and for the JS case, the correct value is text / javascript.
  3. This method is used when defining a small block of code or when you need to include specific default instructions in an HTML document in a website. The main disadvantage is that if you need to make changes to the code block, you need to change all the pages that contain it. The complexity of the method requires developers to learn programming lessons from scratch.
  4. JS instructions can be included in an external JavaScript-type file that XHTML documents reference through a tag. You can create all the necessary files, and each XHTML document will link as many files as needed.

XHTML document.

XHTML Document

In addition to the type attribute, the second method requires the introduction of the src attribute, which specifies the URL corresponding to the JS file. Each tag can link only one file, but on the same page you can include as many tags as necessary.

Files of the JS type are regular text documents with the .js extension, which can be created using any text editor such as Notepad, Wordpad, EmEditor, and UltraEdit.

XHTML Page Code

This last method is used less because it includes JS fragments in the XHTML code of the page. The main disadvantage of this method is that unnecessarily XHTML complicates the maintenance of JS. In general, this method is only used to identify certain events.

Some browsers do not have full JS support, others allow partial blocking. There are users who also completely block JS because they consider it dangerous.

In these cases, if the web page requires JS to function, a warning message appears indicating that JS must be activated.

XHTML Page Code

HTML defines a tag to display a message to a user when his browser cannot execute JS.

Features and limitations

From the very beginning, JS has always been widely used by most internet sites. The advent of Flash diminished its popularity, as it allowed you to perform actions that JS could not.

However, the advent of JavaScript-programmed AJAX applications has regained its popularity. Regarding limitations, it was designed to function in an environment that would allow users to trust JavaScript to run from scratch.

Therefore, JS scripts cannot interact with resources not belonging to the domain from which the script was loaded. Scripts cannot close windows that did not open, and created windows cannot be too small or too large and are placed outside the user's field of vision.

In addition, scripts cannot access files on a computer in either read or write mode and cannot read or change browser settings. Finally, if the script takes a long time to complete, for example, due to a programming error, the browser informs the user that the script is consuming a lot of resources and makes it possible to stop the execution.

The latest browsers available include JS support right up to the third edition of the ECMA-262 standard. The unprecedented popularity of JS as a web application programming language has been extended to other non-network applications and environments. Tools such as Adobe Acrobat allow you to include JS code in PDF files. Other Adobe tools, such as Flash and Flex, use ActionScript, a dialect of the same JS standard. Photoshop allows you to create small scripts through JS, and version 6 of Java includes a new package (named javax.script) that allows you to integrate both languages.

Browser use

Features and limitations

JavaScript allows Benchmark email features to work correctly. Therefore, the user needs to know how to properly configure JavaScript for Windows in the browser.

Internet Explorer 8/9:

  1. Open Internet Explorer browser window.
  2. Click on Tools in the top menu bar and select Internet Options or the Alt key.
  3. Select the "Security" tab.
  4. Click on the button User level.
  5. Scroll through the list of parameters until the name of the scripts appears.
  6. Set Activate Scripts to On.
  7. Click “OK” on each of the next two screens to confirm the change.

Firefox Browser 3.6+:

  1. Open a Firefox browser window.
  2. Click on Tools in the top menu bar and select "Options".
  3. Select the content icon at the top of the window that appears.
  4. Select the Enable JavaScript checkbox.
  5. Click “OK” to confirm the change.

JavaScript from scratch for Chrome 7+:

  1. Click on the key icon on the browser toolbar.
  2. Select options.
  3. Click on the "Advanced" tab.
  4. Click on Content Settings in the "Privacy" section.
  5. Click on JS.
  6. Select "Allow all sites to run JS" (recommended).
  7. Click Close.

All modern browsers interpret integrated JavaScript code on web pages. For interacting with a web page, the JS language for implementing the document object model (DOM) is provided. Traditionally, it was used on HTML web pages to perform operations and only within the client application, without access to server functions. Currently, it is widely used to send and receive information from the server using other technologies, such as AJAX.


All Articles