First, true and false judgment
True: true, not 0 digits, non-empty string, non-empty object
False: False, number 0, empty string, empty object, undefined
Example: if (0) {
Alert (1)
}else{
Alert (2)
}
The result is 2.
Two, JSON and for in
Example: Var obj={aa:1,bb:2,cc:3}
var attr= '; for (attr in obj) {
Alert (attr+ ' = ' +obj[attr])
}
The result is aa=1 bb=2 cc=3
Third, NaN
Not a number is non-numeric and not equal to itself
Use IsNaN (the value to be judged) to detect
Iv. Mandatory (Display) type conversion
parseint () parsefloat ()
Five, implicit type conversion
= = First conversion type and then comparison
= = = (Strict comparison) direct comparison of non-conversion types
-*/(minus multiplication) function: operation if the string is not a number first conversion and then operation
+ (plus) function: 1. String concatenation 2. Arithmetic if it's a string, not a number. stitching
so = = 、-、 *,/implicit type conversion
Vi. Scope of variables
1. Local Variables
function aa () {
var a=11; Local variables: defined in a function, can only be used in this function
}
function bb () {
alert (a);
}
AA ()
BB ()
The result is undefined.
2. Global variables
var A; Global variables: Not defined in any function, can be used anywhere (less recommended)
function aa () {
a=11;
}
function bb () {
alert (a);
}
AA ()
BB ()
The result is 11.
3. Closures
function aa () {
var a=11;
function bb () {
alert (a);
}
BB ()//closures: Child functions can use local variables of the parent function (often in normal conditions of use)
}
AA ()
The result is 11.
VII. Naming conventions
Hungarian Naming Act
Type prefix
Array A
A Boolean value of B
F Floating point float
fn function functions
I integers integer
O Objects Object
Re-regular Expression RegExp
s strings string
V Variant variable variant
Example: Var adiv=getelementsbytagname (' div ')
var Odiv1=getelementbyid (' Div1 ')
Initial capitalization: JS comes with a naming method such as getElementsByTagName
Remember here first, there is a mistake to welcome correct ~
JavaScript Basics Review