码迷,mamicode.com
首页 > Web开发 > 详细

JS---基础知识

时间:2016-03-19 22:32:32      阅读:295      评论:0      收藏:0      [点我收藏+]

标签:

==表示相等,即转换后值相等。

console.log("1.23"==1.23);//true
console.log(0==false);//true
console.log(null==undefined);//true
console.log(new Object()==new Object());//false
console.log([1,2]==[1,2]);//false,对象表示一种引用,只要不是同一个对象,就不相等。

 number==string 转number  1=="1.0"//true
 boolean==? 转number 1==true//true,true转为1,false转为0
  object==number|string 尝试转为基本类型 new String(‘hi‘)==‘hi‘//true

===表示绝对相等,即类型一样,值一样。

console.loconsole.log("1.23"===1.23);//false
console.log(0==false);//false
console.log(undefined===null);//false
console.log(null===null);//true
console.log(NaN===NaN);//false,NaN和任何值比较都不相等。

JavaScript基本类型有number,string,boolean,null,undefined,其中number、string、boolean都有相应的包装类型,分别是Number、String、Boolean

var str="string";

var strObj=new String("string");

str
"string"

strObj
String {0: "s", 1: "t", 2: "r", 3: "i", 4: "n", 5: "g", length: 6, [[PrimitiveValue]]: "string"}

//当我们把一个基本类型尝试去调用其包装类型的方法时,JS会很智能地把基本类型临时转换为包装类型对象,相当于new了一个对象,并值填进去,调用后,该临时对象就会销毁。
var a="string";
alert(a.length);//6
a.t=3;
alert(a.t)//undefine,3是临时对象的值,而此时临时对象已经销毁了。

(123).toString//"123"
相当于new 了一个String对象,并123填进去。

 类型检测:typeof   instanceof   constructor

 

JS---基础知识

标签:

原文地址:http://www.cnblogs.com/beast-king/p/5296285.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!