js一些问题总结

1、undefined与null与NAN的区别

undefined表示未申明,null表示申明了没定义为空值,NAN表示不是数据类型。

2、怎样区别array与object

typeof辨识基本数据类型,instanceof区别复合数据类型,但是各有缺陷,Object.prototype.toString().call(obj) ==='[object Array]'更精准。

instanceof 操作符

JavaScript中instanceof运算符会返回一个 Boolean 值,指出对象是否是特定类的一个实例。 使用方法:result = object instanceof class,成功的返回 true。

3、元素上下左右居中方法
    效果如图所示:
(1)纯css实现
1 .element{
2   width: 600px; height: 400px;
3   position: absolute; left: 50%; top: 50%;
4   margin-top: -200px;    /* 高度的一半 */
5   margin-left: -300px;    /* 宽度的一半 */
6 }

(2)、css+js实现

 

1 .element{
2   width:600px; height:400px;
3   margin:0 auto; /* 实现左右居中,前提是元素有固定宽高*/
4 }

通过js获取参数:margin-top = (winHeigh-eleHeight)/2;

4、js数据类型:

(1)、基本数据类型:number、string、null、undefined、boolean、NAN

(2)、复合数据类型:Object,Array,function

判断数据类型:

 

 
 

 

 

posted @ 2015-07-18 17:26  Amy_Li  阅读(190)  评论(0编辑  收藏  举报