You get a bonus - 1 coin for daily activity. Now you have 1 coin

Introduction to JavaScript

Lecture



  1. What is javascript?
  2. What can javascript do?
  3. What does javascript NOT do?
  4. What is the uniqueness of javascript?
  5. Development trends.
    1. HTML 5
    2. EcmaScript
  6. JavaScript flaws

Let's see what is so special about javascript, why it is, and what other technologies exist besides javascript.

What is javascript?

JavaScript was originally designed to make web pages "live".
Programs in this language are called scripts . They connect directly to HTML and, as soon as the page loads, they are immediately executed.

JavaScript programs are plain text . They do not require any special training.

In this regard, JavaScript is very different from another language, which is called Java.

Why java script

When the JavaScript language was created, it originally had a different name: “LiveScript”. But then the Java language was very popular, and marketers decided that a similar name would make the new language more popular.

It was planned that JavaScript would be such a "younger brother" of Java. However, the history decreed in its own way, JavaScript has grown a lot, and now it is a completely independent language, with its specification, which is called ECMAScript, and has nothing to do with Java.

He has many features that complicate the development, but in the course of the textbook we will deal with them.

To read and execute text in JavaScript, you need a special program - an interpreter. The process of executing the script is called “interpretation” .

Compilation and interpretation for programmers

Strictly speaking, there are “compilers” and “interpreters” for executing programs.

Compilers convert a program into machine code. This machine code is then distributed and started.

And interpreters, in particular, the browser's built-in JS interpreter — get the program in the form of source code. At the same time, the source code itself (script) is distributed.

Modern interpreters convert JavaScript into or close to machine code before execution, and then execute.

A JavaScript interpreter is built into all major browsers, which is why they can execute scripts on the page.

But, of course, these features of JavaScript are not limited. This is a full-fledged language, programs on which you can run on the server, and even in the washing machine, if the corresponding interpreter is installed in it.

What can javascript do?

Modern JavaScript is a “secure” general-purpose programming language. It does not provide low-level means of working with memory, processor, as it was originally focused on browsers in which it is not required.

In the browser, JavaScript can do everything related to page manipulation, interaction with the visitor and, to some extent, with the server:

  • Create new HTML tags, delete existing ones, change element styles, hide, show elements, etc.
  • Respond to the actions of the visitor, handle mouse clicks, move the cursor, press the keyboard, etc.
  • Send requests to the server and upload data without reloading the page (this technology is called "AJAX").
  • Get and set cookies, request data, display messages ...
  • …and many many others!

What does javascript NOT do?

JavaScript is a fast and powerful language, but the browser imposes some restrictions on its execution .

This is done for the safety of users, so that an attacker could not get personal data using JavaScript or somehow harm the user's computer.

There are no such restrictions where JavaScript is used outside the browser, for example on a server. In addition, various browsers provide their own mechanisms for installing plug-ins and extensions that have advanced features, but require special installation actions from the user.

Most browser JavaScript features are limited to the current window and page.

  Introduction to JavaScript

  • JavaScript cannot read / write arbitrary files on the hard disk, copy them, or call programs. It does not have direct access to the operating system.

    Modern browsers can work with files, but this feature is limited to a dedicated directory - “sandbox” . Opportunities for accessing devices are also being worked out in modern standards and are partially accessible in some browsers.

  • JavaScript running in the same tab cannot communicate with other tabs and windows, unless it opens this window or several tabs from the same source (same domain, port, protocol).

    There are ways to get around this, and they are disclosed in the textbook, but they require the implementation of a special code on both documents that are in different tabs or windows. Without it, for security reasons, you cannot get from one tab to another using JavaScript.

  • From JavaScript, you can easily send requests to the server from which the page came. A request for another domain is also possible, but less convenient, since and there are security restrictions here.

What is the uniqueness of javascript?

There are at least three great JavaScript features:

  • Full HTML / CSS integration.

  • Simple things are done simply.

  • Supported by all common browsers and enabled by default.

These three things are no longer in any browser technology at the same time. Therefore, JavaScript is the most common way to create browser interfaces.

Development trends.

Before you plan to explore a new technology, it is useful to get acquainted with its development and prospects. Here in JavaScript everything is more than good.

HTML 5

HTML 5 is an evolution of the HTML standard that adds new tags and, more importantly, a number of new features for browsers.

Here are some examples:

  • Reading / writing files to disk (in a special "sandbox", that is, not any).
  • Built-in browser database that allows you to store data on the user's computer.
  • Multi-tasking with simultaneous use of multiple processor cores.
  • Play video / audio without Flash.
  • 2d and 3d-drawing with hardware support, as in modern games.

Many HTML5 features are still in development, but browsers are gradually beginning to support them.

Trend: JavaScript is becoming more and more powerful and browser capabilities are growing towards desktop applications.

EcmaScript

The JavaScript language itself is improving. The modern standard EcmaScript 5 includes new features for development.

Modern browsers improve their engines to increase the speed of JavaScript execution, fix bugs and try to follow the standards.

Trend: JavaScript is becoming faster and more stable.

It is very important that the new standards HTML5 and ECMAScript retain maximum compatibility with previous versions. This avoids trouble with existing applications.

However, there is a small problem with HTML5. Sometimes browsers try to include new features that are not yet fully described in the standard, but are so interesting that developers simply cannot wait.

... However, over time, the standard changes and browsers have to adapt to it, which can lead to errors in the already written (old) code. Therefore, you should think twice before putting into practice such “super-new” solutions.

In this case, all browsers converge to the standard, and the differences between them are already much smaller than just a few years ago.

Trend: everything goes to full compatibility with the standard.

JavaScript flaws

Often, the disadvantages of approaches and technologies are the flip side of their usefulness. Should I blame the hammer for being heavy? Yes, uncomfortable, but the nails are hammered better.

In JavaScript, however, there are quite objective flaws related to the fact that the language, in the words of its author (Brendan Eich), was made “for 10 sleepless days and nights”. Therefore, some moments are thought out badly, there are also overt mistakes (which the Brendan admits).

We will see concrete examples in the future, since it is more convenient to discuss them in the process of learning a language.

So far it is important for us to know that some of the “weirdness” of the language is not something very clever, but simply were not well thought out enough in due time. In this tutorial, we will pay particular attention to the major flaws and “rakes”. There is nothing critical in them, if you know - you will not step.

In the new versions of JavaScript (ECMAScript) these flaws are gradually removed. The implementation process is slow, primarily due to older versions of IE, but they are gradually dying out. Modern IE is incomparably better in this respect.

Comments

  1. Comments containing additions and questions on the article, and answers to them are welcome.
  2. If your comment concerns a task - open it in a separate window and write there.
  3. For the code inside the line, use the , for the code block - the
     , if more than 10 lines - a link to the sandbox. 
  4. If something is not clear - write what exactly and from what place.
created: 2014-10-07
updated: 2021-03-13
132726



Rating 9 of 10. count vote: 2
Are you satisfied?:



Comments


To leave a comment
If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Scripting client side JavaScript, jqvery, BackBone

Terms: Scripting client side JavaScript, jqvery, BackBone