What are the main features of javascript? What are the characteristics of javascript?

Hello everyone, let me share with you what are the basic characteristics of javascript. Many people still don’t know this. Let’s explain it in detail below. Now let’s take a look!

Introduction to JavaScript

Let’s talk about JavaScript, what you can do with it, what features it has, and some technologies used with it.

What is JavaScript?

The original purpose of JavaScript was to “give life to web pages” GPT rewriting.

We call this programming language script. They can be written in HTML and executed automatically when the page loads.

Scripts exist and execute as plain text. They require no special preparation or compilation to run.

In this regard, JavaScript and Java are very different.

Why is it called JavaScript?

When JavaScript was first born, its name was “LiveScript”. But because Java was so popular at the time, it was decided that positioning a new language as Java’s “little brother” would help its popularity.

With the development of JavaScript, it has become an independent language and has its own language specification ECMAScript. Now, it has nothing to do with Java.

Now, JavaScript can be executed not only in the browser, but also on the server, and even on any device equipped with a JavaScript engine.

Embedded in the browser is a JavaScript engine, sometimes called a JavaScript virtual machine.

Different engines have different “codenames”, for example:

  • V8 – The JavaScript engine in Chrome and Opera.
  • SpiderMonkey – JavaScript engine in Firefox.
  • …There are other codenames like “Trident”, “Chakra” for different versions of IE, “ChakraCore” for Microsoft Edge, “Nitro” and “SquirrelFish” for Safari, and so on.

The names above are easy to remember because they often appear in developer articles online. We will also use these names. For example: for a new feature, if “JavaScript engine V8 is supported”, then we can think that this feature will probably run normally in Chrome and Opera.

How does the engine work?

The engine is complex, but the fundamentals are simple.

  1. An engine (usually embedded in the browser) reads (“parses”) the script.
  2. The script is then converted (“compiled”) into machine language.
  3. The machine language code then runs quickly.

The engine optimizes every stage of the process. It can even monitor compiled scripts at runtime, analyze data flows and apply optimizations to the machine code based on these. Finally, the script will execute very quickly.

What can JavaScript do in the browser?

Modern JavaScript is a “safe” language. It does not provide low-level access to memory or CPU, since it was originally created for browsers that do not require these features.

The capabilities of JavaScript depend heavily on the environment in which it is executed. For example: Node.js allows JavaScript to read and write arbitrary files, perform network requests, etc.

JavaScript in the browser does everything related to web page operations, user interaction, and web servers.

For example, JavaScript in the browser can do the following:

  • Insert new HTML into web pages, modify existing web page content and web page styles.
  • Respond to user actions, mouse clicks or movements, and keyboard strokes.
  • Send network requests to remote servers to download or upload files (so-called AJAX and COMET technologies).
  • Obtain or modify cookies, ask questions, and send messages to visitors.
  • Remember the client’s data (local storage).

What can’t JavaScript in the browser do?

For the sake of user (information) security, the capabilities of JavaScript in browsers are limited. This is mainly to prevent evil websites from obtaining or modifying users’ private data.

Examples of these restrictions are:

  • JavaScript in web pages cannot read, write, copy, and execute files or programs on the user’s disk. It has no direct access to the operating system’s functionality.

    Modern browsers allow JavaScript to do some file-related operations, but this operation is restricted. JavaScript can only operate on this file if the user takes a specific action. For example, “drag” files into the browser, or select files via the tag.

    JavaScript has many ways to interact with cameras/microphones or other devices, but these all require the user’s permission in advance. So a webpage with JavaScript enabled should not be able to secretly activate a webcam to observe you and send your information to the NSA.

  • Different browser tabs are largely unrelated to each other. Sometimes, there are some relationships. For example, one tab opens a new tab via JavaScript. But even in this case, if the two tabs are not opening the same website (websites with different domain names, protocols, or ports), they will not be able to communicate with each other.

    This is the “same origin policy”. In order to solve the “same-origin policy” problem, both tabs must both contain some special JavaScript code to handle this problem, and both allow data exchange, so that the two tabs of the same origin can be realized. Data exchange. This tutorial will cover this part of the relevant knowledge.

    This restriction is also for the user’s information security. For example, the JavaScript of the webpage http://anysite.com opened by the user will definitely not be able to access http://gmail.com (the webpage opened in another tab). Steal information from there.

  • JavaScript can easily communicate with the server of the current web page domain over the Internet. But the ability to get data from the servers of other websites/domains is limited. Although this is possible, it requires explicit protocol (in HTTP headers) from the remote server. This is also for the user’s data security.

JavaScript outside the browser environment generally does not have these restrictions. For example, server-side JavaScript does not have these restrictions. Modern browsers also allow the installation of plug-ins or extensions that may require extension permissions.

What makes JavaScript different?

There are at least 3 things worth mentioning:

 + Fully integrated with HTML/CSS.
 + Use simple tools to accomplish simple tasks.
 + Supported by all major browsers and enabled by default.

The only browser technology that meets these three requirements is JavaScript.

This is why JavaScript is different! That’s why it’s the most common tool for creating browser interfaces.

In addition, JavaScript also supports the creation of servers, mobile applications, etc.

A “better” language than JavaScript

Different people like different features, and JavaScript syntax cannot meet everyone’s needs.

This is normal as everyone’s projects and needs are different.

So, lately there have been a lot of different languages that are compiled (converted) into JavaScript before being executed in the browser.

Modern tools make compilation very fast and transparent, actually allowing developers to write code in another language and automatically convert it to JavaScript.

Examples of these programming languages are:

  • CoffeeScript is syntactic sugar for JavaScript. Its syntax is short, clear and concise. Usually people who use Ruby like to use it.
  • TypeScript focuses on adding strict data types. This simplifies development and can also be used to develop complex systems. TypeScript is developed by Microsoft.
  • Flow also adds data types, but in a different way. Developed by Facebook.
  • Dart is an independent language. It has its own engine for running in non-browser environments (such as mobile applications), and it can also be compiled into JavaScript. Developed by Google.

There are many other languages. Of course, even though we’re using these languages, we need to know JavaScript. Because learning JavaScript allows us to truly understand what we are doing.

Summary

  • JavaScript was originally designed as a language for browsers, but is now used in many other environments.
  • Today, JavaScript is the most widely used language in browsers and is well integrated with HTML/CSS.
  • There are many other languages that can be compiled into JavaScript and provide even more functionality. It’s better to learn about these languages, at least briefly, once you’ve mastered JavaScript.

Modern JavaScript Tutorial: High-quality open source modern JavaScript tutorials from entry to advanced.

Free online reading: http://zh.java.info/

Follow the WeChat public account “Technology Talk” and subscribe for more exciting content.