ArticleDirectory
- Preface
- Variable
- Function
- Condition Statement
- Loop statement
Back to directory
Preface
Before talking about jquery, let's take a look at the basic knowledge issues in JavaScript (later referred to as JS) language.Programming LanguageThe basic knowledge is similar to that of variables, functions, conditional statement blocks, and cyclic statement blocks. However, each language is different in terms of writing, for example, when defining variables in JS, you must use VaR to declare local variables. For weak language JavaScript, you can also do this without adding var, however, if you do not add the variable, you will consider it as a global variable.
Variable
InProgramThe value can be changed during running (haha, as defined in the book more than 10 years ago)
VaRPeople;//Declare a variable named PeopleVaRPeople ="Good boy";//Assign a value to a variable while declaring it. The browser automatically interprets it as a variable of the variable type.VaRAge =23;//Declares a local variable of the integer type.Age =30;//Declares a global variable of the integer type. During program execution, it will not be released.
Function
To implement a functionCodeBlocks are organized together to form a whole. We call it a function, which can greatly reduce the amount of code repetition and make the program clearer.
// Standard writing Funciton hellofun () {alert ( " Hellow world " )} // Variable format VaR Hellofun = Function () {alert ( " Hellow world " )} // A function can have parameters, but it is of a weak type. VaR Hellofun = Function (MSG) {alert (MSG );} // Function call Hellofun ( " Hello World " );
Condition Statement
If there are multiple results for one thing, the condition statement will appear. If the condition is fixed with several values, you can use switch. Otherwise, you can use if... else to check the code.
// Switch instance VaR Inputnumber = Document. getelementbyid ( " Type " ). Value; Switch (Inputnumber ){ Case 1 : Alert ( " Type 1 " ); Break ; Case 2 : Alert ( " Type 2 " ); Break ; Case 3 : Alert ( " Type 3 " ); Break ; Default : Alert ( " Throw new exception () " ); Break ;} // If instance VaR Inputage = Document. getelementbyid ( " Age " ). Value; If (Inputage> 1 & Inputage < 18 ) {Alert ( " Minor " );} Else If (Inputage> = 18 & Inputage < 70 ) {Alert ( " Adult " );} Else If (Inputage> = 70 ) {Alert ( " Elderly " )} Else {Alert ( " Incorrect form filling " );}
Loop statement
That is, when a condition is attached, a code block is repeatedly executed. We can use while, for, and so on.
//For LoopVaRArr = [1,2,3]For(VaRI =0, J = arr. length; I <j; I ++) {Console. Log (ARR [I]);//The result is displayed on the Firefox console.}
In fact, in the JS world, the execution performance of code is also very exquisite. Our Writing Performance in the for statement is not wrong, but if it is written below, the performance will decrease, because every time
The length of the ARR is evaluated.
//For LoopVaRArr = [1,2,3]For(VaRI =0; I <arr. length; I ++) {Console. Log (ARR [I]);//Poor performance}
Now, I will write down the basic JS programming knowledge here. Starting from the next time, I will introduce jquery-related knowledge. Thank you for reading this article!
Back to directory