1.比较
javascript字符串在进行大于(小于)比较时,会根据第一个不同的字符的ascii值码进行比较,当数字(number)与字符串(string)进行比较大小时,会强制的将数字(number)转换成字符串(string)然后再进行比较
console.log('13'>'3'); // 输出:false
console.log(5>'6'); // 输出: false
console.log('d'>'ABDC') // 输出: true
console.log(19>'ssf') // 输出 false
console.log('A'>'abcdef') // 输出 false
2.运算符 undefined, null, “” ,0 ,NAN ,false 转为布尔值都为false
&& || !
&& 看到假的就返回
两个表达式 ==> 先看第一个表达式转换为布尔值的结果,如果结果为真,那么他会看第二个表达式转换为布尔值的结果,然后如果只有两个表达式的话,只看到第二个表达式,就可以返回该表达式的值var a = 1 && 2 ==>2;
如果第一个为假。则返回第一个的值var a = 0 && 2 ==>0;
三个表达式 ==>原理也是一样。先看第一个
短路语句 2>1 && document.write(‘test’);==>test
|| 跟&& 相反,看到真的就返回
a = 0 && false && 2 ==>2
! 将值转为布尔值然后取反
3.条件语句
if...while
while(true){}
switch case
switch(){
case “”:
break;
}
continue;
不往下执行(终止本次的循环) ,但是继续循环
初识引用值
- 数组
- 对象
编程形式的区别
- 面向过程(按照步骤,顺序来)
- 面向对象(谁能干啥,谁能干啥)
类型转换
- typeof
- number
- string
- boolean
- object
- undefined
- function
- ypeof(“123”); 返回的都是string类型的
- typeof(null);==>object
- 显示类型转换方法:
- Number(); //a,undefined ==>NaN null == >0
- parseInt();
- //转为整形的数 只能是数子 true undefined不是数字的都转为NaN
- parseInt(num,numIndex);//numIndex 进制 将别的进制转为十parseInt(2,8);八进制的2转为十进制 2
- parseInt(10,2)==>2
- parseInt(100,2)==>4
- parseInt(demo,16);
- parseFloat()
- toString(radix);//null undefind 没有toString()
- var num = 10;
- num.toString(8); 将十进制转八进制
- String();
- Boolean()
隐式类型转换
- isNaN();
- var abc = “123”;
- isNaN(abc) ==> Number(abc) 是不是NaN;
- ++a / +a / -a
- ++ : + : - 转Number
- && ||
- true ==>1
- false ==>0
- false>true ==>false
- 2>1>3==>false
- undefined == null ==>true
- NaN == NaN ==> false
- 不发生类型转换 === 和 !==
- alert(a) 报错 为定义
- console.log(typeof(a)) ==> undefind 是字符串类型的