This is the first article in the study notes series. As before, I will introduce some basic knowledge, including the basic concepts of js, JScript variables, js data types, and 3. JScript operators, js process control, and js functions. For more information, see
Basic Concepts
Javascript is an interpreted language, and the browser acts as an interpreter. The js execution engine does not execute a row or a row, but analyzes and executes a row or a row.
Delayed script
The defer attribute is defined in HTML4.0.1. Its purpose is to indicate that the script does not affect the Page Structure during execution. That is to say, the script will be executed after the whole page is parsed. Therefore, setting the defer attribute in the script element is equivalent to telling the browser to download the file immediately, but the execution is delayed. In the XHTML document, set the defer attributedefer=“defer"
Asynchronous script
html5
Defines the async attribute for script. The entire attribute is similar to the defer attribute and is used to change the script processing behavior. Similarly, like defer, async only applies to external script files and tells the browser to download files immediately. However, unlike defer, scripts marked as async are not necessarily executed in the specified order.
The purpose of specifying async is to prevent the page from waiting for the script file to be downloaded and executed, so as to asynchronously load other content on the page. Therefore, it is recommended that the asynchronous script do not operate the DOM during the loading.
Case Sensitive
All variables, function names, and operators in ECMASCript are case sensitive.
1. JScript Variables
The variable is set to memory when it is used for the first time, so that it can be referenced in the script later. Declare variables before using them. You can use the var keyword to declare variables.
Var count, amount, level; // multiple declarations declared with a single var keyword.
Variable name
Variable names include global variables, local variables, class variables, and function parameters.
Variable names are composed of prefix types and meaningful words. The camper naming method is used to increase the readability of variables and functions. For example, sUserName and nCount.
Prefix specification:
Each local variable must have a type prefix, which can be divided:
S: string. For example, sName, sHtml; n: indicates a number. For example: nPage, nTotal; B: Indicates logic. For example, bChecked, bHasLogin; a: indicates an array. For example, aList, aGroup; r: indicates a regular expression. For example, rDomain, rEmail; f: indicates a function. For example, fGetHtml, fInit; o: indicates other objects not involved, such as oButton, oDate; g: indicates global variables, such as gUserName and gLoginTime;
JScript is a case-sensitive language. Follow the following rules to create valid variable names:
Note that the first character cannot be a number.
It can be followed by any letter, number, or underline, but cannot be a space.
Variable names must not be reserved words.
javascript
Is a weak language,JavaScript
Extra spaces are ignored. You can add spaces to the script to improve readability.
var
Yesjavascript
The reserved word, indicating that the following is the description of the variable, the variable name is a user-defined identifier, and the variables are separated by commas.
If a variable is declared but not assigned a value, the variable exists and its value is Jscript value undefined.
Forced type conversion
In Jscript, operations can be performed on different types of values without worrying about exceptions in the JScript interpreter. Instead, the JScript interpreter automatically changes (forced conversion) One of the data types to another, and then executes the operation. For example:
The calculation result value is added together with the string to forcibly convert the value to a string. Adding a Boolean value to a string forcibly converts a Boolean value to a string. Adding a value to a Boolean value forcibly converts a Boolean value to a value.
To explicitly convert a string to an integer, useparseInt
Method. To explicitly convert a string to a number, useparseFloat
Method.
JavaScript
Variable Survival: After you declare a variable in the function, you can only access the variable in the function. After exiting the function, the variable is revoked. This type of variable is called a local variable. You can use local variables with the same name in different functions, because only the declared functions can recognize each of these variables.
If you declare a variable outside the function, all functions on the page can access the variable. The lifetime of these variables starts after they are declared and ends when the page is closed.
Js variable Mind Map
2. js Data Type
Jscript has three types: main data types, composite data types, and special data types.
Main (basic) Data Types
Boolean string value
Composite (reference) Data Type
Object Array
Special Data Types
Null`Undefined`
String data type: the string data type is used to represent the text in JScript. In JavaScript, although double quotation marks ("") and single quotation marks ('') can represent strings, there is almost no difference between them. However, only double quotation marks ("") are used to indicate that the string is considered optimal.
A string value is a string of zero or more Unicode characters (letters, numbers, and punctuation marks ).
What is Unicode?
Unicode provides a unique value for each character, no matter what platform, program, or language. Unicode is developed to provide unified encoding for all characters in the world.
Numeric data type
We need to understand that JScript internally expresses all the values as floating point values, so there is no difference between integer and floating point values in Jscript.
Boolean data type
Boolean (logical) can have only two values: true or false.
Js array and Object
For more information, see my article-> javascript learning Summary--array and object Section
Null data type: You can assign a null value to a variable to clear the content of the variable.
In Jscripttypeof
Operator will reportnull
The value isObject
Type, rather than typenull
.