What are the uses of javascript?, the role and function of javascript

Hello everyone, the editor is here to answer the following questions for you, javascript and the role of javascript, what are the uses of javascript? Now let us take a look together!

This article mainly introduces the benefits of enabling java in the browser. It has certain reference value. Friends in need can refer to it. I hope you will gain a lot after reading this article. Let me take you through the usage of python for statement.

3 functions, 5 characteristics, and 5 major data types of JavaScript
  • 1. The functions of 3 javaScripts
    • 1.JavaScript form validation to reduce server pressure
    • 2. Page special effects
    • 3. Interaction effect
  • 2. 5 JavaScript Characteristics
    • 1. Weak type
    • 2. Interpreted languages
    • 3. Case sensitive
    • 4.Scripting language
    • 5. Browser analysis
  • 3. Five basic JavaScript data types
  • 4. Summary

1. The functions of three javaScripts

  1. JavaScript form validation, reducing server pressure
  2. Page effects
  3. Interactive effects

Only by being familiar with the function of JavaScript can we understand and use JavaScript properly, and be familiar with why we need to learn JavaScript. What effect does learning JavaScript have on writing front-end code?

1. JavaScript form validation, reducing server pressure

JavaScript can be used to validate these input data in HTML forms before the data is sent to the server.
Typical form data validated by JavaScript are:

  1. Has the user filled out the required fields in the form?
  2. Is the email address entered by the user legal?
  3. Has the user entered a valid date?
  4. Did the user enter text in the numeric field?

When communicating with QQ, the QQ client is in the LAN. When you open QQ and log in to the QQ server, your client establishes a long connection with the QQ server through the external network. You can use netstat-bn to see that the status of this connection is established. You must verify your true identity when logging in. Not everyone can connect to the server, and you need to bind your mobile phone number and other credentials that can confirm your true identity. This allows a user to only register one account (there are also people who registered early, when there were fewer people online, and the server did not put forward such strict requirements, so now there are also cases where some users have multiple QQ accounts), login ID. Another example is Baidu Netdisk. Baidu Netdisk is a kind of virtual storage space. Registering an account will automatically allocate 2T of network storage space. Assuming that each person registers n accounts, then one person can theoretically have a capacity of 2*n T. When When n approaches infinity, can the server still work? ? What if the number of people is larger? ? Obviously, when sending a connection request to the server, verifying the identity and limiting the number of registered users can reduce the pressure on the server.

2. Page special effects

Provides an example of a real-time clock, calling the time through the built-in Date object in JavaScript, dynamically changing the detection time in real time, and displaying it on the web page. The following two pictures are renderings. They are very cool. Every time the time changes, small balls will hit them.
Animation renderings 1
Animation renderings 2
If you need it, please contact me and I can provide you with your dynamic real-time clock code.

3. Interactive effect

Interactive effects are also one of the major functions of JavaScript, which are particularly important for programmers. The renderings and codes are given directly here.
Interactive renderings

// An highlighted block
<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<title></title>
</head>

<body>
<>
//First type: define variables first, then assign values
varnum1;
num1 = 2;
//Second type: Assign value while defining variable
var num2 = 3.5;
//The third type: direct assignment
num3 = 4;
//Print to the console, through the built-in console and its method log
console.log("num1=" + num1,"num2=" + num2,"num3=" + num3);
</>
</body>

</html>

2. 5 JavaScript characteristics

  1. Weak type
  2. Interpreted Language
  3. Case sensitive
  4. Scripting language
  5. Browser parsing
    A deep understanding of the five characteristics helps us understand JavaScript code, so that when we write code and read other source code, we know why, improve efficiency, and have our own logic and organization.
1. Weak type

Variables have no definite type and are variable. The variable type is only related to the current value type
Variables are defined in JavaScript through var (variable-variable). There are usually three ways to define variables, as shown in the following code:
The first method: define variables first, then assign values
varnum1;
num1 = 2;
The second type: assigning values while defining variables
var num2 = 3.5;
The third type: direct assignment
num3 = 4;

// An highlighted block
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<>
//First type: define variables first, then assign values
varnum1;
num1 = 2;
//Second type: Assign value while defining variable
var num2 = 3.5;
//The third type: direct assignment
num3 = 4;
//Print to the console, through the built-in console and its method log
console.log("num1=" + num1,"num2=" + num2,"num3=" + num3);
</>
</body>
</html>

var defines data type
Verify that JavaScript is a weakly typed language. The function typeof is a unary operator (the number of operations is only one, such as the increment/decrement operator + +, –). The code is attached below:

// An highlighted block
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<>
//Define a String data type
var str = "I Love you my friend!";
//Print the data type of str
console.log(typeof str);
//Assign str to number data type
str = 10;
//Print the data type of str
console.log(typeof str);
//Assign str to Boolean data type
str = false;
//Print the data type of str
console.log(typeof str);
//Assign str to object data type (array in JavaScript is object type)
str = [1,5,6];
//Print the data type of str
console.log(typeof str);
//Define an unassigned data type
varnum;
//Print the data type of str
console.log(typeof num);
</>
</body>
</html>

Effect picture:

2. Interpreted language

Parse from top to bottom in the JavaScript domain, execute while parsing (Tips in development: When referencing other people’s JavaScript files, you should Put it before the JavaScript code you wrote)
Here is an example. In the JavaScript language, verification is executed from top to bottom. What would happen if an undefined variable is output to the console first? ? There are only two situations: 1. It can be printed out, 2. It cannot be printed out. Answer: Of course it cannot be printed, and the system will report an error. As shown below:

3. Case sensitive

Go directly to the code to test it. I still recommend that you use the code to check whether this is the case. Here I paste the code and the renderings of the experiment.

// An highlighted block
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<>
//Define different variables a and A, one lowercase and one uppercase
var a = 10;
var A = 100;
//The console prints a and A
console.log("a = " + a," A = " + A)
</>
</body>
</html>

Rendering

4. Scripting language

Scripting language Also known as extended language, or dynamic language, it is a programming language used to control software applications. Scripts are usually saved in text (such as ASCII) and are only executed when called. interpret or compile.
Script languages (Script languages, ing programming languages, ing languages) are computer programming languages created to shorten the traditional edit-compile-link-run (edit-compile-link-run) process.

5. Browser analysis

3. Five basic JavaScript data types

1. undefined data type (undefined value == null value, refers to an unassigned variable)
2. number data type
3. boolean data type
4. String data type
5. Object data type (null value, array, built-in object, custom object, function function)

JavaScript only has these data types. Since JavaScript is a weakly typed language, the data types between them can be converted to each other. We have already introduced them in 2.1 above when introducing weak types, so I won’t go into details here. Still inheriting the previous style, let’s go directly to the code and renderings to see if this is the case. I have read some blogs, and some say there are 6 types. Here I attribute function to the object class because function is a subclass of object. Specifically, function is a “callable object”. However, compared with ordinary objects, function objects have an internal [[Call]] method to indicate that the object is callable. When the typeof operator determines the Object, if the [[Call]] method is implemented internally, it will Return function.
Code:

// An highlighted block
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<>
//Define a variable
varnum;
//Print the data type of str
console.log(typeof num);
//Verify that null==undefined
console.log(num == null)//Values, etc., types are not equal (null is object type, undefined is undefined type)
//Define a String data type
var str = "I Love you my friend!";
//Print the data type of str
console.log(typeof str);
//Assign str to number data type
str = 10;
//Print the data type of str
console.log(typeof str);
//Assign str to Boolean data type
str = false;
//Print the data type of str
console.log(typeof str);
/*
* 1. Array
* 2.null
* 3. Built-in objects (date, Math)
* 4. Custom objects
* 5. function is a special object
*/
//1.Array
str = [1,5,6];
//Print the data type of str
console.log(typeof str);
//Define an unassigned data type
//2.null
console.log(typeof null);
//3.Built-in objects
console.log(typeof Date);
console.log(Date instanceof Object);//Date object is a function and its parent type is object, so it is of object type
//4. Custom type
//Assign the str variable to a custom object class
str = {name:"Zhang San",age:15,profession:"student"};
console.log(typeof str);
\t\t
//function function
//Define a function function
function basicType(){
\t\t\t
}
console.log(typeof basicType);
console.log(basicType instanceof Object);//Displaying true indicates that it is an object type
</>
</body>
</html>

Run result graph:

4. Summary

This article mainly explains JavaScript’s 3 functions, 5 features, and 5 basic data types. To refute the six major data types of some bloggers, the function function belongs to the Object type, and the code and verification code are attached.