Today: December 3, 2022 7:15 pm

Introduction to JavaScript

In this tutorial, we want to see what special features there are in JavaScript? What can we achieve with it? And how do other technologies use it?

What is JavaScript ?!

The JavaScript language was originally created to "animate web pages". The programs in this language are called scripts. They can be written right in the HTML of a web page and run automatically when the page loads.

Scripts are presented and executed in plain text. They do not require special preparation or assembly to perform. In this respect, JavaScript is very different from another language called Java.

Why is this language called JavaScript?

When the JavaScript language was created, it was originally called "LiveScript". But Java was very popular at the time, so it was decided to help establish a new language as Java's "little brother". But with evolution, JavaScript, with its own specification called ECMAScript, became a completely independent language and now has nothing to do with Java.

How do engines work?

Engines are complex. But their principles are simple. The engine (embedded in the browser) reads the text ("parses"). It then "compiles" the script into machine language. And then the device code runs very fast.

The engine applies optimization at every stage of the process. It even watches the compiled script at runtime, analyzes the data it goes through, and optimizes machine code based on this knowledge.

What can JavaScript do in the browser?

Modern JavaScript is a "safe" programming language. It does not provide access to low-level memory or CPU, as it was originally created for browsers that do not require it.

The capabilities of the JavaScript language depend largely on the environment in which it runs. For example, Node.js supports functions that allow JavaScript to read / write custom files, execute network requests, and more.

JavaScript language in the browser can do everything related to web page manipulation, user interaction and web server.

Example

For example, JavaScript in a browser can:

Add new HTML to the page, change existing content, change styles.
React to user actions, perform mouse clicks, pointer gestures, keystrokes.
Send requests over the network to remote servers, download and upload files (so-called AJAX and COMET technologies).
Receive and set cookies, ask the visitor questions, show messages.
Remember client-side data ("local storage").

What can JavaScript not do in the browser?

JavaScript capabilities in the browser are limited due to user safety. The purpose is to prevent a bad webpage from accessing private information or damaging user data.

Examples of these restrictions are:

  • JavaScript on a web page can not read / write, copy, or execute custom files on the hard disk. Does not have direct access to operating system functions.
  • Modern browsers allow you to work with files, but access is limited, and access is restricted only if the user performs certain actions, such as "dropping" the file in the browser window or selecting it by tagging.
  • There are ways to interact with the camera / microphone and other devices, but these methods require the explicit permission of the user. Therefore, a page with JavaScript may not activate the webcam in the language, monitor the environment and send the information to the NSA.
  • Different tabs / windows usually do not know each other. Sometimes they do this, for example when one window uses JavaScript to open another window. But even in this case, JavaScript from one page may not be able to access another page (if from different sites (from another domain, protocol, or port).

Source

This is called "policy of the same origin." To solve this problem, both pages must agree to exchange data and contain a specific JavaScript code that manages it. We will address it in the tutorial.

This restriction is for the safety of the user. A page from http://anysite.com opened by a user should not be able to access and steal another browser tab with the URL http://gmail.com.

  • JavaScript can easily connect to the server from which the current page came from over the network. But its ability to receive data from other sites / domains is paralyzed. Although it is possible, it requires explicit agreement (expressed on HTTP headers) from a distance. Once again, this is a safety limitation.
JavaScript language

If you use JavaScript outside of a browser, for example on a server, there is no such restriction. Modern browsers also allow plugins / extensions to request long-term permissions.

What makes JavaScript unique?

There are at least three interesting things about the JavaScript language:

Full integration with HTML / CSS.
Simple tasks are done simply.
Support is enabled by all major browsers by default.
JavaScript is the only browser technology that combines the three.

This is what makes JavaScript unique. This is why it is the most widely used tool for creating browser interfaces.

As mentioned, JavaScript also allows you to create servers, mobile applications, and more.

JavaScript language

JavaScript languages


JavaScript does not fit everyone's needs. Different people want different characteristics.

This is to be expected, because projects and requirements are different for everyone.

So recently a bunch of new languages have appeared that are being converted to JavaScript before running in the browser.

Modern tools make printing very fast and transparent. It actually allows developers to code in another language and automatically turn it "under the hood".

Examples of these languages:

CoffeeScript is a syntax sugar for JavaScript. This introduces a brief command and allows us to write clearer and more precise code. Ruby developers usually like it.
TypeScript focuses on simplifying "accurate data typing" to simplify the development and support of complex systems. Made by Microsoft.
Flow also adds data typing, but in a different way. Developed by Facebook.
Darts is an independent language that has its own engine. Which works in non-browser environments (such as mobile applications). But it can also be ported to JavaScript. Made by Google.
Brython is a Python to JavaScript server. Which makes it possible to write programs in pure Python without JavaScript.
Kotlin is a modern, concise, and secure programming language that can target the browser or Node.
There are more. Of course, even if we use one of the transferable languages, we need to know JavaScript to really understand what we are doing.

Summary

  • JavaScript was originally created as a browser-only language, but is now used in many other environments.
  • Today, JavaScript has a unique position as the most widely used browser language with full HTML / CSS integration.
  • There are many languages that "translate" to JavaScript and offer certain features. After mastering JavaScript, it is recommended that you take a brief look at them.

Source: The text of this article has been translated and taken from the official JavaScript site .

With Alfa Cyber Stay tuned to stay up to date.

, , , ,
0.00 avg. rating (0% score) - 0 votes
0 Comments

No comment

en_USEnglish