javascript基础

来源:互联网 发布:java语言发展历史 编辑:程序博客网 时间:2024/06/07 00:52
var a="undefined";var b="false";var c="";function aa(n){if(n){ alert(true);  }  else{   alert(false);  }}aa(a);//trueaa(b);//trueaa(c);//false

a、b、c都是字符串型的变量,只有c变量为空,转换成boolean才为false.

console.log(1+'2'+'2');//122console.log(1++'2'+'2');//32console.log("A"-'B'+'2');//NAN2console.log("A"-'B'+2);//NAN
if(! "a" in window){var a=1;}alert(a);//undefined

hasOwnPeoperty:用来判断一个对象是否有给出名称的属性或对象,注意的是该方法无法检查该对象的原型链中是否具有该属性,该属性必须是对象本身的一个成员。
isPrototypeOf:用来判断要检查其原型链的对象是否存在制定对象实例中,存在返回true,不存在返回false.

typeof 判断变量类型(基本上是基本变量类型),
返回值有string,boolean,number,undefined,null,object,function
格式:res=typeof variable

instanceof 判断对象的类型
返回值为true,false
格式:res=variable instanceof constructor

 console.log("one");  setTimeout(function(){console.log("two");},0); console.log("three"); 打印结果为:one  three  two alert("2"+3+4);//234