0 |
0 |
0 |
0 |
0 |
0 |
1 |
|
var v2 = 5 >> 2 = 00000001(2) = 1(10)
Operator additional content:
Assignment operator: In fact, it is a basic assignment operator: =, which means to put the data on the right side of the equal sign into the variable on the left side of the equal sign.
The wrong grammar: 的
var v1 = 1, v2 = 2, v3 = 5, v4 = -2;
V1 + v2 = v3 + v4; // wrong, big mistakes, big mistakes
Compound assignment operator: += -= *= /= %=
The precedence of operators - too many, too complicated to remember, but please remember a few rules:
1. Be careful: operators have priority (sequence) issues.
2, Parentheses have the highest priority, and the equal sign (assignment) has the last priority.
3, Multiply and divide first, then add and subtract
4. If you can’t think clearly or understand something, use brackets to solve it
5, Parentheses are only parentheses, which can be nested layer by layer.
Example:
var year = 2013;
闰 // Judging the leap year: a year can be removed by 4 and cannot be removed by 100, or it can be removed by 400, and it is also a leap year.
{ document.write( year + "It's a leap year") ;}
Data value transfer method:
var v1 = 10;
var v2 = v1; //Copy the middle value of v1 and put it into the variable v2 - this can also be said to be "pass the value of v1 to v2"
var v1 = v1 + v1; //The value of v1 changes, but it does not affect v2 - because v2 itself is also an independent variable.
document.write("
v1=" + v1); //20
document.write("
v2=" + v2); //10, no, 40,
The above "v2 = v1" is called "copy by value" - get the value of v1, make a copy, and then assign it to v2
var v3 = {name:"小花", age:18, edu:"University"}; //This is a so-called "object" type - it includes 3 pieces of data.
//Operation of the data is similar to this:
document.write("
The age of the v3 object is: " + v3.age);
v3.age = 19; //The value of the age data of the v3 object is repeatedly assigned a new value, similar to the previous v1 = 20;
var v4 = v3; //At this time, the "memory address" of the v3 variable is passed to the v4 variable, and the data of the v3 object itself is actually only obtained from this address. ——This is called reference by value——At this time, the two variables actually have the same data content, similar to multiple names of a person: real name, stage name, screen name, nickname
document.write("
The age of this object in v4 is: " + v4.age);
v3.age = 20; //
document.write("
At this time, the age of the object v4 is: " + v4.age);
Summary:
本 In JS, the basic data type uses "copying and passing value" -the new data when the value is passed (of course, it is also represented by another variable)
数 Compound data type (array and object) uses "reference values" -the value of the value when the value is passed, and the data still has only one copy, and the two variables point to the same data.
if branch structure:
Control structure: It is to use a certain syntax to control the flow of our program execution - it can also be called "process control structure"
Branching is "multiple paths, take one".
Simplest form:
//If this condition is met (that is, the result of the conditional judgment is true), the statement block within it will be executed, otherwise nothing will be done.
if(Conditional judgment statement)
{
// Statement block to be executed - statement block is actually a general term for "n statements".
}
Choose one branch form: The meaning is that there are two roads, one must be taken.
if(Conditional judgment statement)
{
// Statement block 1 to be executed - executed when the previous condition is true
}
else
{
// Statement block 2 to be executed - executed when the previous condition is not true
}
Multiple choice branch structure: Take one of the multiple paths according to the satisfaction of the conditions, but it is also possible to take none of them:
if(Conditional judgment 1) //If this condition is met, statement block 1 will be executed, and then the if will end
{
// Statement block 1
}
else if (condition judgment 2) //If condition 1 is not satisfied, then judge condition 2: if it is satisfied, execute statement block 2 and end if
{
// Statement block 2
}
else if (Conditional judgment 3) //If condition 2 is not satisfied, then judge condition 3: If it is satisfied, execute statement block 3 and end if
{
// Statement block 3
}
………………………………………… . . . . . If none of the conditions are met, nothing will be executed at the end and the if will end.
Comprehensive type:
if(Conditional judgment 1) //If this condition is met, statement block 1 will be executed, and then the if will end
{
// Statement block 1
}
else if (condition judgment 2) //If condition 1 is not satisfied, then judge condition 2: if it is satisfied, execute statement block 2 and end if
{
// Statement block 2
}
else if (Conditional judgment 3) //If condition 2 is not satisfied, then judge condition 3: If it is satisfied, execute statement block 3 and end if
{
// Statement block 3
}
…………………… . . . . .
else
{
//The last else statement block. //This statement block will be executed when none of the previous conditions are met.
}
Note: In the comprehensive form, there must be one branch (statement block) that will be executed.
switch branch structure:
The overall meaning of the branch structure of switch is similar to that of if, which also means "take one of many paths". Its usage form is:
switch (a variable or expression) //Whether it is a variable or an expression, it ultimately represents a "value", we use v1 to speak
{
case Fixed value 1: //If v1 is equal to the value 1, statement block 1 will be executed
break;
out out out out out out my''''''s‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ with with 2�
// Statement block 2;
break;
case ………………………………
. . . . . . . . . . . . . . . . .
T Default: // If the previous judgments are not established (that is, not equal), this sentence will be executed.
//Default statement block
}
Special note: if statements can actually use very flexible conditional judgments, such as > judge.
while loop structure:
The basic concept of circulation:
1. A loop is to execute certain programs (blocks of statements) repeatedly
2. There must be a way to stop the loop - the computer does not have its own judgment ability to decide "I'm tired, I won't do it anymore"
Basic syntax form of while loop:
while (Conditional judgment) //If the conditional judgment is met, the statement block will be executed, otherwise the while will end.
{
// Statement block to be executed
} // If this statement block is executed, it will immediately return to the previous while position to continue judging.
The above forms are only basic requirements in grammar, but in "practical" situations, you usually need to follow the following pattern:
【Loop variable initialization】
while ( 【Loop variable as conditional judgment】 )
{
[Change of loop variable value]
}
do while loop structure:
The do while loop is a loop structure that will be executed once first, and then decide whether to continue execution and loop based on the judgment condition.
The practical form of do while is as follows:
【Loop variable initialization】
do
{
[Change of loop variable value]
} while ( [Loop variable as conditional judgment] ) ;
Description: First execute the statement block in brackets after do, and then perform the conditional judgment in the while statement. If the judgment is true (true), continue to return to the above do to execute the statement block in curly brackets, otherwise it will end.
for loop structure - recommended use:
Basic form of for loop:
for( [Initialization of loop variable A]; [Loop variable as conditional judgment B]; [Change of loop variable value C] )
{
// Loop body D, which is the statement block to be executed repeatedly
}
Execution logic (sequence) of for loop:
A è Bètrue è D è C è Bètrue è D è C è Bè
"
Function
Functions are not numbers.
A function is just a grammatical construct.
A function is a grammatical structure that "packages" several lines of code and uses them as a whole.
A function can be said to be a syntax that needs to be defined and used - similar to a variable: it needs to be defined and used.
A function is designed to accomplish a specific function and is usually a "function that needs to be executed repeatedly" - the purpose of a function is to execute the code blocks (statement blocks) wrapped in it
A function is an independent execution space, that is, the code inside it can be considered "separated" from the code outside the function.
Definition form of function:
function function name (formal parameter 1, formal parameter 2, ... )
{
//The statement block to be executed - the function body
}
var s1 = parseInt(3.5); //3
var s2 = parseInt(3.8); //3
var s3 = parseInt(3.1); //3
var s4 = parseInt(3.0); //3
var s5 = parseInt(3); //3
——parseInt is actually a function—a system internal function. This function has the "magical ability" to convert a number given to it into a corresponding integer, which is the largest integer not larger than the given number.
Make a request:
I want to find the hypotenuse corresponding to the two right-angled sides 3 and 4.
I also want the hypotenuses corresponding to balls 5 and 6, as well as 7 and 8, and so on. . . . . . . .
What exactly is a function? Functions are just the grammatical embodiment of modular programming ideas - the so-called modular programming idea is to make various "repeated tasks" into independent "modules" and "call them directly" when used, thus saving the need for repeated tasks. The code to write.
Function calling form:
Function name (actual parameter 1, actual parameter 2, ..... );
Function calling process:
1, First, the actual parameter values at the calling function are passed to the formal parameters at the function definition in one-to-one correspondence.
a) The formal parameter must only be a "variable name", which represents a certain actual meaning - depending on the function function.
b) The actual parameter must only be one "data" (may be direct data or variable data)
c) Note: Variable names in formal parameters cannot use var, nor can they be defined elsewhere.
2, Then the execution flow of the program enters the function, and "all statements" in the function are executed according to the appropriate flow
3. After the execution of the program inside the function is completed, the execution flow of the program will return to the location of the function call.
a) If the task performed by the function requires a return value, the return statement must be used to return the value. At this point the function naturally ends.
b) If a function does not need to return a value, the return statement can also be used. At this time, it just indicates that the function will end here immediately (all statements may not be fully executed)
Two cases of function return values:
There is a return value: it means that the function will obtain a data after a certain "calculation" (execution), and the data will be returned to the calling location (caller). At this time, you must use "return a certain value;" to achieve it. ——For example: if the boss takes a certain amount of money and tells an employee to buy a train ticket, the employee needs to return the purchased train ticket to the boss.
Special note: when there is a return value, the function call should be treated as a value.
Is there a functional return value that is not determined by grammar, but determined by the actual needs -grammar is only changed according to actual needs.
表示 No return value: It means that a function simply executes the code in the execution. After the execution is completed, there is no need to return a data to the "caller".
Parameters of the function: There are no grammatical regulations at all. Instead, it is decided according to the needs of the application itself whether there are parameters or how many parameters there are-that is, to complete the function of the function, what necessary data should be provided, and this data is The reaction is the formal parameter of the function, and each formal parameter represents a certain meaning (data).
Scope of variables
The so-called scope refers to "effective and available range"
There are two types of scope:
Global scope: A scope that is available (valid) in all program scopes.
域 Local action scope: A range that can be used (valid) can be used only within a specific range (usually inside the function).
Variables are divided into two types from the perspective of scope:
Global variable: refers to a variable that can be used in the global scope (valid). Variables defined outside a function are global variables. Global variables can be used both outside and inside functions.
Local variable: refers to a variable that can only be valid within a specific scope (usually a function) - usually inside the function where the variable is defined
System internal functions
parseInt(xxx): Convert parameter xxx into an integer - rounding operation.
parseInt(3);
parseInt( 3.8);
parseInt(3.1);
parseInt(“3”); è 3
parseInt( “3.8” ); è 3
parseInt( “3.1” ); è 3
parseInt( “3abc” ); è 3
parseInt( “3.8abc” );è 3
parseInt( “3.1abc” );è 3
parseInt( “abc3” ); è NaN
parseInt( “abc 3.8” );è NaN
parseInt( “abc3.1” );è NaN
parseInt( “abc” ); è NaN
NaN - It is a special number (type number), its meaning is: Not a Number - This situation usually means that a number is required but the data provided is not a number or cannot be converted to When a number. ——The number NaN is not equal to any number, including itself.
parseFloat(xxx): Convert parameter xxx to a decimal.
parseFloat (3);
parseFloat ( 3.8);
parseFloat ( 3.1 ); è 3.1
parseFloat (“3”);
parseFloat ( “3.8” );
parseFloat (“3.1”);
parseFloat ( “3abc” ); è 3
parseFloat ( “3.8abc” );
parseFloat ( “3.1abc” ); è 3.1
parseFloat ( “abc3” ); è NaN
parseFloat ( “abc 3.8” );
parseFloat ( “abc3.1” ); è NaN
parseFloat ( “abc” ); è NaN
Number(xxx): Convert parameter xxx into a "number" - pay attention to compare with parseFloat.
Number ( 3 ); è 3
Number (3.8); è 3.8
Number (3.1);
Number (“3”); è 3
Number ( “3.8” ); Number ( “3.8” );
Number (“3.1”);
Number (“3abc” );
Number ( “3.8abc” ); è NaN
Number (“3.1abc” ); è NaN
Number (“abc3”);
Number ( “abc 3.8” ); è NaN
Number ( “abc3.1” ); è NaN
Number (“abc”);
isNaN(xxx): Determine whether the parameter xxx is a "not a number" - if it is a non-number, the result is true, otherwise if it is a number, the result is false
) Isnan (3); è False
isNaN (3.8);
isNaN (3.1);
isNaN (“3”);
3 Isnan ("3.8"); è False
isNaN (“3.1”); è false
isNaN (“3abc” );
3 Isnan ("3.8ABC"); è true
isNaN (“3.1abc” );
isNaN (“abc3”);
isNaN ( “abc 3.8” );
isNaN (“abc3.1”);
isNaN (“abc”); è true
The above introduces the PHP basic learning notes (3), including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.