JavaScript programming language: structure, features, learning

Table of contents:

JavaScript programming language: structure, features, learning
JavaScript programming language: structure, features, learning
Anonim

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

JavaScript history

History of JavaScript
History of JavaScript

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

JavaScript is a registered trademark of Oracle Corporation. It is used with a license from products created by Netscape Communications and current organizations such as the Mozilla Foundation under the direction of Brendan Icke. Microsoft created their JS dialect JScript as a name to avoid branding issues. JScript was adopted in version 3.0 of Internet Explorer, 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 specs

In 1997, the authors proposed to adopt the JavaScript programming language as a standard of the European Computer Manufacturers Association ECMA. In June 1997, it was adopted under the name ECMAScript, and soon after, also as ISO/IEC-16262.

The language specification governing JavaScript is called ECMAScript. The structure of Ecma International that reviews and adopts changes is called Technical Committee 39 or TC39. ECMA has published several standards related to ECMAScript. The first edition was published in June 1997. A year later wereminor 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 arrived in 2009, then was republished 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

ECMAScript 2019 candidates are ready, TC39 proposals are in stage 4, it is expected to be released in June this year. You can try the novelty today, some functions are interspersed with JavaScript in utilities. If they are disabled by default, then you can easily start them in your browser settings. The standards are described in more detail in books on JavaScript, which can be downloaded for free on the Internet at specialized sites.

Server Side JS

Netscape introduced server-side scripting for the 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 brightest examples, which 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 glory and caught the attention of other developers. As a result of this, there has been an increase in the set of general-purpose frameworks and libraries. This made it possible to improve programming methods withuse of the language and extend the use of JS beyond web browsers, as evidenced by the spread of the JavaScript framework on the server side.

Imperative and structured

JavaScript is compatible with much of the C programming structure, such as the use of if statements, for loops, switch clauses, and more. JavaScript 1.7 added support for block scoping with the let keyword. Like C, JS distinguishes between expressions and sentences. The syntactical difference from C is the automatic insertion of semicolons, which means that in JS those that end sentences can be omitted.

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

JS is made up almost entirely of objects - associative arrays enhanced by the use of prototypes. Properties and their values can be created, modified/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 like Functiony Date.

First class functions

JavaScript includes an eval function that allows expressions to be evaluated 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, with this moreprogramming lessons from scratch will carefully help you figure it out.

First class functions have properties and methods like.call() and.bind(). A nested function is one that is defined within another that is created whenever the outer function is called. In addition, each forms a closure that is the result of evaluating a domain containing one or more dependent variables from another environment, including constants, local variables, and calling function arguments. The result of evaluating the specified closure is part of the object's internal state, even after the outer function has completed its actions.

Prototypes instead of classes

Prototypes instead of classes
Prototypes instead of classes

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

Functions also behave like constructors. Prefixing the call with the new keyword creates a new prototype instance that inherits the properties and methods from the constructor, including the properties of Object. ECMAScript 5 introduces the Object.create method, which allows instantiation without the need to automatically inherit from Object. In earlier environments, the prototype may have been created as null. The prototype property of the constructor defines the object for the internal newly created prototype. New methods can be added by changing the object's prototype, as a constructor.

Runtime environment

Runtime
Runtime

The JavaScript programming language typically depends on a runtime environment, such as 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 providing the ability to include or import scripts, such as in HTML using a tag. This is not a language feature, but it is common in most JS implementations.

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

As with many scripting languages, arrays and objects can be created with a shortened syntax, so a developer will always need a JavaScript programming language tutorial at hand. In fact, these literals form the basis of the JSON data format. JavaScript also supports regular expressions similar to Perl, which provide a concise and powerful syntax for text processing, more complex than the functions built into string objects.

Differences: Java & JavaScript

Differences: Java & JavaScript
Differences: Java & JavaScript

JS language is very different from Java, JavaScript has much more possibilities. Although it is an object-oriented programming language, itdoes not have inheritance, unlike Java, so JS is an event-targeted language.

Another difference between both languages is that while Java can create stand-alone applications such as applets, programs that are included in web pages, JavaScript is built into the web, forming part of the HTML code without which it cannot exist..

The two languages share much of the same syntax, structure, establishing a hierarchy of objects to define 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, just like a server in PHP documents. This code is included in HTML tags such as. JS distinguishes between uppercase and lowercase letters and is mainly used to create dynamic web pages.

Include 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
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 to define the code in the title of the document.
  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 case of JS the correct value is text/javascript.
  3. This method is used when defining a small block of code or when you want to include specific default instructions in a website's HTML document. The main disadvantage is that ifyou 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 familiarize themselves with programming lessons from scratch.
  4. JS statements can be included in an external JavaScript type file referenced by XHTML documents via a tag. You can create all the necessary files, and each XHTML document will link as many files as needed.

XHTML document.

XHTML Document
XHTML Document

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

JS type files are plain text documents with a.js extension that can be created with any text editor such as Notepad, Wordpad, EmEditor and UltraEdit.

XHTML code

This last method is less used because it includes JS snippets in the page's XHTML code. The main disadvantage of this method is that XHTML unnecessarily complicates JS serving. In general, this method is only used to detect some events.

Some browsers don't 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 will appear indicating that theJS.

Code for XHTML pages
Code for XHTML pages

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

Possibilities and limitations

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

However, the advent of AJAX applications programmed in JavaScript has brought the language back into popularity. In terms of limitations, it was designed to function in an environment that would allow users to trust the execution of JavaScript scripts from scratch.

Thus, JS scripts cannot interact with resources outside of the domain from which the script was loaded. Scripts cannot close windows that were not opened, and created windows cannot be too small or too large and placed out of the user's view.

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

The most modern browsers available include support for JS 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 applications andnon-network environments. Tools like 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 usage

Opportunities and limitations
Opportunities and limitations

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

Internet Explorer 8/9:

  1. Open an 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 User level button.
  5. Scroll through the list of options until the script name appears.
  6. Set Enable Scripts to On.
  7. Press "OK" on each of the following two screens to confirm the change.

Firefox Browser 3.6+:

  1. Open the 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. Check the Enable JavaScript checkbox.
  5. Press "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 under "Privacy".
  5. Click on JS.
  6. Select "Allow all sites to execute JS" (recommended).
  7. Click Close.

All modern browsers interpret embedded JavaScript code in web pages. To interact with a web page, the JS language is used to implement the Document Object Model (DOM). Traditionally, it was used in HTML web pages to perform operations and only within the client application, without access to server functions. It is currently widely used to send and receive information from the server along with other technologies such as AJAX.

Popular topic

Editor's choice

  • IPv6 protocol: setup on Windows systems
    IPv6 protocol: setup on Windows systems

    Probably, many users of computer systems, delving into the network settings, noticed that in the list of protocols, in addition to the well-known IPv4, there is also the sixth version (IPv6)

  • View history on computer
    View history on computer

    Today you can learn about almost all the actions taken on the computer. It's about browsing history

  • Computer technology hardware: definition, description and types
    Computer technology hardware: definition, description and types

    Modern computers to ensure maximum performance and correct operation use hardware and software that are very interconnected and clearly interact in different directions. Now let's touch on the consideration of hardware, since initially it is they who occupy a dominant position in ensuring the operability of any computer or even mobile system

  • Keyboard shortcuts and the evolution of operating systems
    Keyboard shortcuts and the evolution of operating systems

    It takes about a minute to copy or move a file from one location to another using the menu system. The developers introduced a keyboard shortcut that replaced all these actions and made it possible to reduce the time of this common operation by 3 or more times. True, for this it was necessary to slightly modernize the keyboard: new keys were added - "Ctrl", and later - "Windows"

  • If the torrent does not download
    If the torrent does not download

    An article for those who consider the ability to download files from torrent trackers a convenience, not an echo of the past. Not only the unavailability of "high-speed" tariff plans is the reason for the choice, but also personal preferences