Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the application scenarios of JavaScript

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "what are the application scenarios of JavaScript". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn what are the application scenarios of JavaScript.

JavaScript is a programming language and belongs to a high-level language. It is a scripting language (interpretive language) for front-end development.

Interpretive languages, that is, programs can be run directly without compilation before execution. The representatives of interpretive languages that parse and execute at runtime are: Python, JavaScript, PHP, Ruby interpretive languages with good cross-platform, some web scripts, server scripts and auxiliary development interfaces. Programs that do not require high speed and compatibility between different system platforms usually use interpretative languages.

All in all, JavaScript is a highly interpreted scripting language

The composition of JavaScript:

ECMAScript, which is the syntax standard of JavaScript, DOM:JavaScript manipulates elements on the web page, APIBOM:JavaScript manipulates the browser part of the function of API

Insert a "digression":

When you see JavaScript, you can't help but think of Java, so what's the connection between them?

In fact, JavaScript was originally inspired by Java, one of the purposes is to look like Java, so there are grammatical similarities, some names and naming conventions are also borrowed from Java. The similarity between the names of JavaScript and Java is due to the fact that NetScape reached an agreement with Sun for marketing considerations (because Java was so popular at that time, it was renamed JavaScript "rub heat").

Characteristics of JavaScript:

① is easy to use: you can write it using any text editing tool; you can execute the program with a browser.

② interpretive execution (interpreted language): does not compile in advance, executes line by line, and does not require strict variable declaration (variables are all declared in var).

③ is object-based: a large number of off-the-shelf objects are built in, and a small number of programs can be written to achieve the goal.

Use the scene:

With the improvement of the language JavaScript, we can use it for front-end development, back-end development and mobile development. Of course, the first breakthrough in learning the language is front-end development. Today or in the future, JavaScript seems to be capable of anything--

Diversity of application scenarios:

Page special effects mobile development (RN, Weex) server development (Node.js) command line tool (Node.js) Internet of things and artificial intelligence (Ruff) game development (cocos2d-js)

1) HTML: used to make a web page. Simply speaking, it is to write the structure of a web page and provide the content in the web page.

2) CSS: beautify the web page, 2D/3D transition, animation, etc.

3) JavaScript: control the content of the web page, add dynamic effect to the web page, realize the bridge between the web page and the customer, and make the web page have rich vitality. Some data operations in the web page are completed by using JavaScript.

The process of a web page gradually owning HTML, CSS, and JavaScript (shown here with reference to the net map):

There are three formats: in-line, in-page and out-of-chain.

Inline expression (there can be two types of representations):

1) (the alert () method is used to display a warning box with a specified message and an OK button)

2)

As shown in the figure:

In-page style: similar to CSS in-page style, but it is usually written at the end of the page for two reasons:

1) the web page is loaded from top to bottom, and the js code usually adds interaction (operation element) to the tag, so you need to load HTML first, otherwise if the HTML has not been loaded when the js code is executed, then the js code will not be able to add interaction (operation element)

2) after the tag appears in the HTML page, the page pauses to wait for the parsing and execution of the script. Regardless of whether the current script is embedded or chained, the download and rendering of the page must stop and wait for the script to complete before continuing.

As shown in the figure:

The function outside the code here is to load JS after all the contents of the window have been loaded. Many people are used to putting this function on when writing JS code, and then start writing something inside.

Outer chain: also put at the tail

As shown in the figure:

Some points for attention in the outer chain style:

1) js code cannot be written in the outer chained script code block, and it will not be executed even if it is written, that is, it is useless to write like this in the following figure.

2) since a request is sent each time a chained JS file is loaded, which consumes a lot of performance, it is recommended to package multiple JS files into a single JS file in enterprise development to improve the performance and loading speed of the web page.

Pop up a display box in the web page to display the information (using the alert () method)

Output messages in the console, which are generally used to debug programs

Open it with a browser and press F12, then click on the Console console to see the output. And you can also see the line number on the right side of the console, which is easy to locate.

Of course, except that we can write or refer to Console objects.

The demonstration is shown below:

Output content to body

Of course, in addition to writing text here, you can also write labels, all of which can be written as long as the text is written.

Please refer to the HTML DOM write () method

A pop-up input box in a web page, which is usually used to receive messages entered by the user

It can be called through window, or you can prompt () and either directly, but there are some differences.

(if you write it in a function, those called through window will normally wait for the window content to be loaded, while those directly used by prompt () will load first, blocking the loading of web page content. In this case, it is recommended to write directly.)

Please refer to the Window prompt () method

A prompt box pops up in a web page to display information. This method is generally used in conjunction with judgment statements.

The pop-up prompt box can be selected to confirm / cancel

Please refer to the Window confirm () method

Single-line comments:

Multiline comments:

Note when using comments: single-line comments can nest single-line comments, multi-line comments can nest single-line comments, but multi-line comments cannot nest multi-line comments! You can deepen your impression through your own practice.

Some minutiae:

1) pay attention to syntax specification when writing Javascript. At the end of a line of code, you must add it at the end of the code.

(if you do not write a semicolon, the browser will automatically add it, but it will consume some system resources; in addition, it is easy to add the semicolon incorrectly, so the semicolon must be written in development.)

2) it is strictly case-sensitive in JavaScript (correct √), (error ×)

3) multiple spaces and line breaks are ignored in JavaScript

Literal quantity: literal quantity is a value, the value of a variable or the value of a constant, such as numbers, letters, strings. However, literals are not usually used directly

Variable: can be used to save literals, and the value of the variable can be changed at will

Constant: data that is fixed and cannot be changed after the definition is completed. There is no method to declare constants before ES6. Const has been added to ES6 to define constants. It is recommended that the names of constants are all capitalized. If they are composed of multiple words, they can be separated by underscores. (for example, const needs to be used in an ES6 environment)

Use of variables:

1) declare variables: use the var keyword in JS to declare a variable, for example: var name; var age; (also var name, age;)

2) assign values to variables: name = "Henry"; age = 19

3) var name = "Henry"; var age = 19; (or var name = "Henry", age = 19;)

Then output debugging

Difference:

1) the difference between constants and variables: constants and variables are stored in the same way, except that constants must have initial values, and values are not allowed to be modified, while variables can have no initial values and can be assigned multiple times.

2) the difference between constant and literal quantity: constant and literal quantity will not be changed, constant is the container for storing data, while literal quantity is the value to the right of equal sign, literal quantity is a string or numerical value composed of strings, numbers, etc.

1) definition: everything in JS that can be named independently by the developer can be called an identifier (for example, variable name, function name, attribute name all belong to identifiers)

2) naming rules:

Identifiers can contain letters, numbers, underscores, $identifiers cannot start with numbers, identifiers cannot be keywords in ES or reserved word identifiers generally use hump naming method in JS underlying identifiers are Unicode coded, so all characters in UTF-8 can be used as identifiers

At this point, I believe you have a deeper understanding of "what are the application scenarios of JavaScript?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report