JavaScript(二)(未整理完)

javascript操作符

算术运算符

- 算术运算符有:+,-,*,/,%,++,--
对于算术运算符要注意的是:字符串和数字之间的相加减,以及布尔值类型和字符,数字之间的相加减

var numa = 10;
var numb = 4;
console.log(numa+numb); //14
console.log(numa-numb); //6
console.log(numa*numb); //40
console.log(numa/numb); //2.5
var str = “1”;
console.log(numa+str); //101
console.log(numa-str); //9
console.log(numa+true); //11
console.log(numa-false); //10
console.log(numa+null); //10
console.log(numa+undefined); //NaN
console.log(0.1+0.2); //0.30000000000000004

赋值运算符

- 赋值运算符有:=,+=,-=,*=,/=

var num = 10;
console.log("=",num); //= 10
num += 5; //num = num + 5
console.log("+=",num); //+= 15
num -= 4; //num = num - 4
console.log("-=",num); //-= 11
num /= 3; //num = num / 3
console.log("/=",num); // /= 3.6666666666666665
num = 2; //num = num * 2
console.log("
=",num); //*= 7.333333333333333
num %= 1; //num = num % 1
console.log("%=",num); //%= 0.33333333333333304

比较运算符

- 比较运算符有:>,>=,<,<=,==,===(全等)
- 比较运算符只会返回布尔值:true/false

var a = 10;
var b = 15;
var c = ‘10’;
console.log(a>b); //false
console.log(a>=b); //false
console.log(a<b); //true
console.log(a<=b); //true
console.log(ac); //true
console.log(a
=c); //false

逻辑运算符

- 逻辑运算符有:&&(与),||(或),!(非)
- 以下在进行判断的时候为假
1.0
2.null
3.undefined
4.NaN
5.' '(空字符串)
6.false
需要注意:逻辑运算符两边的数值均为布尔值,或者其他数据类型

var a = 10>4 && 3>4;
console.log(a); //false
var b = 10>5 && 3>2;
console.log(b); //true
var c = 1>2 || 2<5;
console.log©; //true
var d = 1 || 0 || ‘’;
console.log(d); //1
var e = 22 && undefined || null;
console.log(e); //null
var f = !0;
console.log(f); //true
var g = 10 || 3 && false;
console.log(g); //10
var h = 1 && null && undefined;
console.log(h); //null

javascript流程控制

JavaScript(二)(未整理完)

javascript循环

javascript字符串方法

javascript数组方法