精通JS 笔记

一,javascript数据类型:undefined,null,boolean,number,string,object 五种加一种复杂类型. 注意大小写,区分大不写
函数:function
typeof 返回数据类型没有null,但有function.如typeof(null)返回object
1.1特还有:
typeof(NaN) typeof(infinity) => number
typeof(undefined) =>undefined
1.2逻辑:
undefined,null,"",0 => false 但只能 undefined==null true 其它返回 false
二,== && ====
==, 两边值类型不同的时候,要先进行类型转换,再比较。
===,不做类型转换,类型不同的一定不等。
"123"==123, "0123"==123 =>true; "0123"==0123 => false ;原因是0123当作8进制转换成10进制。。所以要注意这些细节
三,注意javascript是<script>段执行,function 预编译。这是什么意思,上例子
<script>
function a(){alert('1')};a()
function a(){alert('2')};a();
</script>
两条输出都是2。
<script>
function a(){alert('1')};a()
</script>
<script>
function a(){alert('2')};a();
</script>
输出分别是1,2。

 四,

obj.call(要替换的执行环境,参数1, 参数2,……,参数n);
object.apply(要替换的执行环境,[参数1, 参数2,……,参数n ]);

var name = 'global';
var person = {
name: 'zero'
};

function printInfo(age, job) {
console.log(this.name, age, job);
}
// 直接调用
printInfo(20, 'test');
printInfo.call(person, 20, 'test');
printInfo.apply(person, [20, '前端工程师']);
printInfo.bind(person)(20, '前端工程师');

this,arguments,eval(),call(obj)把obj变成this,prototype

for(var s in afunction)
alert(s+ "is a" +typeof(afunction[s]));

arguments用法

function area () {if(arguments.length == 1) {

  alert(3.14 * arguments[0] * arguments[0]);
  } else if(arguments.length == 2) {
  alert(arguments[0] * arguments[1]);
  } else if(arguments.length == 3) {
  alert(arguments[0] + arguments[1] + arguments[2]);
  } else {
  return null;
  }
  }
  area(10,20,30);
原文地址:https://www.cnblogs.com/jayruan/p/5094067.html