javascript小知识

if判断中的值是一个对象、非空字符串、非零数字或true时,判断会评估为真;而当值是一个null、undefined、0、false、NaN或空字符串时评估为假。

列:if(name){ alter("true")}

检测属性是否存在时,有另外的两种方式:in和hasOwnProperty(),前者会检测原型属性和自有(实例)属性,后者只检测自有(实例)属性。

console.log("age" in per1);  //true
console.log(per1.hasOwnProperty("age"));  //true
console.log("toString" in per1);  //true
console.log(per1.hasOwnProperty("toString"));  //false

二:null值表示一个对象的空指针,typeof 检测null 时返回“object”

var a = null;
alert(typeof a);//"object"

undefined 派生值null ,所以alert(null == undefined);//true

三:Boolean 类型

<pre name="code" class="javascript">var message = "hello word";
var messageBoolean = Boolean(message);//true



 

四:Number 类型:

1.NaN 即(not a number).NaN 与任何值都不相等,包括本身,alert(NaN == NaN);//false

2.isNaN() ;会帮我们确定这个参数是否“不是数值”。isNaN()在接收到一个值之后,会尝试将这个值转化为数值。某些不是数值的值会直接转换为数值,列如:字符串“10”

或Boolean值。而任何不能被转换为数值的值都会导致这个函数返回true。

alert(isNaN(NaN)) //true
alert(isNaN(10)) //false
alert(isNaN("10")) //false
alert(isNaN("helloword")) //true
alert(isNaN(true)) //false






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值