Brief javascript knowledge point
Basic Javascript Language
1. Js is a scripting language for web development.
2. Script Language
1) It cannot be used independently. It is used in combination with html/jsp/php/asp/asp.net, between html and c, c ++, java, and c #;
2) script languages include variables, functions, and control statements;
3) The scripting language is an explanatory language (the source code is executed during execution)
4) js is interpreted and executed in the browser.
3. javascript execution on the browser client
4. Because js is interpreted and executed by the browser, there is a problem here. Different types of browsing may have different support for js.
5. Development Tools
1) notepad
2) eclipse
6. Start the case
1) Case 1: hello world displayed on the webpage
<Script lanauage = "javascript">
Window. alert ("hello ");
</Script>
A. Js can be anywhere
B. Js must be wrapped in <script>. If no, the browser regards it as plain text.
C. Multiple <script> fragments can appear in an html (jsp php asp) file, and the browser will execute them sequentially.
2) Case 2: add the preceding
<Scriptlanauage = "javascript">
// The definition of variables in js. Variables in js are represented by var regardless of the actual type.
Var num1 = 45;
Var num2 = 89;
Var result = num1 + num2;
Window. alert ("result is" + result );
</Script>
7. How to determine the type of js variables?
1) is a language of the weak data type
2) the data type of variables in js is determined by the js engine.
8. js naming rules (variables and functions)
1) Use uppercase/lowercase letters, numbers, _, and $ to name them.
2) cannot begin with a number
3) JavaScript keywords and reserved words cannot be used.
4) case sensitive
5) Comment ///**/
9. js Data Type
1) Basic Data Types
A. Value var a = 89; var B = 35.0;
Special values: NaN window. alert (parseInt ("abc"); inifinity window. alert (6/0 );
B. String "a book of JavaScript" 'abc'
C. Boolean
Note: You can see the specific data type of the variable through typeof.
<Scriptlanguage = "javascript">
Var v1 = "abc ";
Var v2 = 890;
Window. alert ("typeof (v1) =>" + typeof (v1 ));
Window. alert ("typeof (v2) =>" + typeof (v2 ));
V1 = 567;
Window. alert ("typeof (v1) =>" + typeof (v1 ));
</Script>
2) composite Data Types
A. Array
B. Object
C. Special Types
Null
Udefine example
Var tt; window. alert (tt); undefined
Window. alert (tt); error undefined
10. js data type conversion
1) automatic conversion
2) forced conversion
Var a = "12345 ";
A = parseInt (a); // use the system function to force the conversion.
11. js Operators
+ ,-,*,/
% Can be used to determine whether two numbers can be divisible.
++ Operator
--Operator
12. javascript control statements
1) Sequential Control
2) Branch Control
A. Single Branch
B. Dual Branch
Basic syntax
If (conditional expression)
{
}
Else
{
}
C. Multiple branches
Basic syntax
If (conditional expression)
{
}
Else if ()
{
}
...
Else
{
}
D. Switch statement
<Script language = "javascript">
Var a = "890 ";
Switch ()
{
Case "890 ":
Window. alert ("890 ");
Break;
Case "90 ":
Window. alert ("90 ");
Break;
Default:
Window. alert ("no matching ");
}
</Script>
The switch statement of Js allows js to support any types (except arrays and objects)
The data types after Case can be arbitrary (except for arrays and objects)
Break jumps out of the entire switch
13. In logical operations, 0, "", false, null, udefined, and NaN indicate false.
Important knowledge points:
| The first value not false or the last value (if all values are false) will be returned ).
| The returned result is not necessarily a Boolean value.
14. js also has bitwise AND shift operations
15 Functions
① Why functions are required
② Basic probability of a function
Function () Function name (parameter list)
{
// Code
Return value;
}
Functioncalculator (num1, num2, operator) // do not include var before the parameter name
{
Var res = 0;
Switch (operator)
{
Case '+ ':
Res = num1 + num2;
Break;
Case '-':
Res = num1-num2;
Break;
Case '*':
Res = num1 * num2;
Break;
Case '/':
Res = num1/num2;
Break;
}
Returnres;
}
Put forward the above functions separately, write them to the js file, and then introduce them as needed.
<Scriptlanguage = "javascript" src = "myfunction. js"> </script>
16 function call Method
① Normal call
Function Name (parameter list)
② Call by pointing to the function variable
Var myvar = function name
Myvar (actual parameter)
17 variable parameters
JavaScript Functions naturally support variable parameters.
Abc2 (1, 3, 4, 8 );
Function abc2 ()
{
For (var I = 0; I
{
Window. alert (arguments [I]);
}
}