JS笔记

弱类型特性

var num=32;
num="string";
32+32//64
"32"+32//"3232"
"32"-32//0

数据类型

1.原始类型
number
string
boolean
null
undefined
2.对象类型(object)
Function
Array
Date
...

隐式转换

"37"-7//30
"37“+7//377
//转换类型
num-0
num+"
NaN和任何数据===都返回false,包括NaN
new Object不等于new Object

包装对象

var a="string";
alert(a.length);//6
a.t=3;
alert(a.t);//undefined

"str"=>String Object a=>length
访问完毕后,String Object将被销毁

类型检测

1.typeof

eg.

typeof 100//"number"
typeof (undefined)//"undefined"
typeof new Object()//"object"
typeof [1,2]//"object"
typeof NaN//"number"
typeof null//"object"

2.instanceof
obj instanceof Object

eg.

[1,2] instanceof Array===true
new Object()instanceof Array===false

不同window或iframe间的对象类型检测不能使用instanceof

3.Object.prototype.toString

eg.

Object.prototype.toString.apply([])==="[object Array]";
Object.prototype.toString.apply(function(){})==="[object Function]";

4.constructor
5.duck type

表达式

原始表达式

1.常量、直接量

3.14,"test"

2.关键字

null,this,true

3.常量

i,k,j

eg.

10*20
10//原始表达式
*//运算符
10*20//复合表达式

你可能感兴趣的:(JS笔记)