In this article, I will introduce you to the basic content of javascipt-the details you need to pay attention to. If you need it, please refer to it.
Javascip-basic--- Notes for details:
1. Special values: NaN, Infinity, isNaN (), isFinite ()
NaN:
The Code is as follows:
Var a = parseInt ('a123 ');
Window. alert (a); // output NaN
Infinity:
The Code is as follows:
Window. alert (6/0); // output Infinity (it is better not to write this)
IsNaN (): determines whether it is a number. If it is not a number, true is returned. If it is a number, false is returned.
The Code is as follows:
Var a = "dd ";
Window. alert (isNaN (a); // return true
IsFinite (): used to determine whether it is infinite. If number is NaN (not a number) or positive or negative infinity, false is returned.
The Code is as follows:
Window. alert (isFinite (6/1); // return true
Window. alert (isFinite (6/0); // return false
2. logical operators:
In logical operations, 0, "", false, null, undefined, and NaN indicate false.
(Or |) | returns the first value (the object can also be) other than false, or the last value (if all values are false)
This knowledge point is widely used in javascript frameworks.
A,
The Code is as follows:
Var a = true;
Var B = false;
Var c = B |;
Window. alert (c); // Output true
B,
The Code is as follows:
Var a = 2;
Var B = 0
Var c = a | B;
Window. alert (c); // returns the first value and outputs 2
C,
The Code is as follows:
Var a = false;
Var B = "";
Var c = 0;
Var d = new Object (); // Object
Var aa = a | B | c | d; // a, B, and c are all false.
Window. alert (aa); // return d (object)
4. multi-branch switch
The Code is as follows:
Var flag = 1;
Switch (flag ){
Default:
Window. alert ("nothing ");
Case 'A ':
Window. alert ("");
Case 'B ':
Window. alert ("B"); // if no break statement exists and no matching is successful, all results are output.
}
The Code is as follows:
Var flag = 1;
Switch (flag ){
Default:
Window. alert ("nothing ");
Case 'A ':
Window. alert ("");
Case 1:
Window. alert ("B"); // No break statement. If the match is successful, the break statement is no longer found. At this time, B is output.
}
5. function call
Func. js
The Code is as follows:
Function abc (val ){
Window. alert ("abc ()" + val );
}
// Functions with returned values
Function test (num1, num2 ){
Var res = 0;
Res = num1 + num2;
Return res;
}
// Functions without return values
Function noVal (num1, num2 ){
Var res = 0;
Res = num1 + num2;
}
Function call:
The Code is as follows: