A .
1. What is JavaScript?
A scripting language interpreted language
weakly typed language: the data type of the variable value determines
2, JavaScript what constitutes?
The core ECMAScript
the DOM
BOM
3, how to use JavaScript?
Tag write js code in the Script
writing js code in an external js file, you need to js files introduced
in the property (event attributes, etc.) tag inside to write js code is not recommended
4, variables
declared in memory for some can store variable amount
var variable name = value;
naming variable name:
not begin with the number
allowed by numbers, letters, underline, and $
not use the keywords and reserved words
hump
$ name
data type
number can represent decimal integers and 32-bit integer can be represented 64-bit floating-point
string need '' or '' is included in a character string representing the type of two
Boolean
undefined
null
reference data type (subsequent repeat)
var. 1 = a ". 1"
operation
string + Number = string
string + boolean = string
number + boolean = number
number + undefiend = NaN
boolean + undefiend = NaN
string + undefiend = string
js a function
isNaN (data) of the digital detection data is non
mandatory data type conversion
toString () data .toString () to convert any data string
parseInt (data) to convert the data type is an integer type, number
parseInt ( "2a5. A64 ") 2
parseFloat (data)
parseFloat (" 1.9a2 ") 1.9
number the (data) contains non-numeric characters long, returns NaN
Two arithmetic operators
Arithmetic Operators + - * /% + -
++ / - as a prefix to increment / decrement in the use as a suffix to increment / decrement
There num 5;
whether ++; // num = num + 1
console.log (whether); 6
console.log (num--); 6
console.log (whether); 5
console.log (whether ++); 6
var r = whether ++ ++ ++ whether num +;
console.log(r) 22
console.log(num) 9
num ++ 6 plus from 1, and then used for the next operation 7
++ num 8 plus 1, and then from the next operation for 8
++ num 8 from one (9)
First priority * /% + again - if you want to elevate the priority of use ()
35+ 2*18/3 + 12/6%4; 49
(35+ 2)*18/(3 + 12)/6%4; 3.4
rounding
// rounding error .toFixed solution (n) n where n is a decimal reserved
Change 2 = var - 1.6;
the console.log ( 'the change:' + change);
Change = change.toFixed (2);
the console.log ( 'rounded:' + change);
Please enter a user determines a parity is odd or even number determination
= prompt ( "Enter a number:") InputNum var;
the console.log ( "odd?" + (InputNum% 2) );
Three relational operators
> <> = <= ==! = ===! == final result must be a boolean
var str = '100';
where n = 100;
1.string number and size is determined, the number is converted to a string type implicitly by Number () function
console.log(str>5); true
2. Any data is compared with a NaN, the results are necessarily false (* 30a is converted to NaN)
console.log('30a'>5) flase
Analyzing between 3.string string and comparing it with the size of the code for each character unicode
console.log('a'>'b'); (a 的 ASCII97 b 98)
IV. Bitwise operator
1. & bitwise and
Convert binary operands on both sides become, each of the numbers, as long as the correspondence is 1 when the result was this bit is 1, otherwise the result bit is 0
can only do digital operations, and want to convert binary numbers in doing arithmetic
was num1 = 5, num2 = 2;
was r = num1 and num2;
console.log (s); // 1
// 5 binary: 101
// 2 binary: 010
// r 000
Action: determining parity, is more efficient than the mold, with a determined number, do bitwise last one is an odd number 1, 0 is an even number
the console.log ((. 1 & 10) === 0); // to true
the console.log ((. 9 &. 1) === 0); // flase
10 binary 1010
1 Digital 0001
results 0000
2. Bitwise or |
Converting the binary operands become both sides, there is a 1, the numbers on each of the bit compare junction, if two numbers is 1, otherwise 0
was num1 = 5, num2 = 2;
was r = num1 and num2;
console.log (s);
Binary 5: 101.
. 7 Binary: 010
R & lt 111. 7
Rounding down, will certainly bit operation data into binary numbers, decimals are converted to an integer
var num3 = 6.5;
the console.log (num3 | 0);
6.5 ==>. 6 110
0 000
110. 6
3. Rotate Left
<< Bitwise left shift, the binary number, a few to the left, to the right of 0 to fill the seats,
console.log (4 << 2) moves to the left two
0000 0000 0100 (4) ---->> 0000 0001 0000 (16)
4. bitwise right
console.log (8 >> 2) to the right two
0000 0000 1000 (8) -----> > 0000 0000 0010 (2)
5. XOR
The binary number is converted to both sides
Compare the numbers on each, only one is 1, the result was this bit is 1, otherwise 0
was num1 = 5;
was num2 = 2;
r = num1 ^ num2
console.log(r); 7
* Exchange value of num1 and num2
num1 = num1 ^ num2;
// ^ = num1 num2;
num2 = ^ num1 num2;
// ^ = num1 num2;
^ = num1 num2;
// num1 = num1 ^ num2;
console.log(num1,num2);
V. assignment operator
+= -= *= /= %= &= |= ^=
Unary
// ++ -!
// binary operators
// + - * /% & && || ^ |> <
// ternary operator
Expression 1 Expression 2:? Expression 3
Expression 1: Type boolean operation result should
@ 1 = true expression of executing the expression 2
// 1 = false performed Expression Expression 3
// allows nested
Analyzing results, if the score> = 80 excellent
> = 60 passing
<60 failed * /
var score = prompt ( "Enter the grade:");
var msg = Score> = 80 "excellent": score> = 60 "qualified": "fail";??
console.log (msg);