程晓晖

博客园 首页 新随笔 联系 订阅 管理

2011年1月28日 #

摘要: var temp = new Array(); temp["abc"] = "abcd"; temp[1] = 2; temp[8] = 3; temp[2] = "";// temp[2] = null;// temp[2] = undefined;// for (var t in temp) {// alert(t);//循环弹出 abc 1 8 2 不会弹出其他的(比如说3)// }// alert(temp["abc"]);//弹出abcd// alert(temp[3]); //弹出undefined if (temp[2]) {//temp[2]不是null 或者不是“”或者是0 阅读全文
posted @ 2011-01-28 19:10 fumen 阅读(123) 评论(0) 推荐(0) 编辑

摘要: 今天遇到一个有趣的问题,就是在用javascript的parseInt函数时,parseInt("08")或者 parseInt("09")返回的居然是0,而parseInt("01")...parseInt("07")都是正确的,一开始很难理解,后来发现出现这个问题的原因是当在前面有"0"时,javascript会认为这是一个八进制数,而"08"和"09"不是一个合法的八进制数,所以导致了那个问题,但是parseFloat不会存在这个问题。 事实上,parseInt方法有一个可选参数来表示数字的进制,所以这应该不能算是一个bug,只是我们平时没有注意到这种细节问题。那么解决的方法很简单,就是 阅读全文
posted @ 2011-01-28 19:10 fumen 阅读(3967) 评论(0) 推荐(0) 编辑

摘要: 运算数为数字 typeof(x) = "number" 字符串 typeof(x) = "string" 布尔值 typeof(x) = "boolean" 对象,数组和null typeof(x) = "object" 函数 typeof(x) = "function" typeof 运算符返回一个用来表示表达式的数据类型的字符串。 可能的字符串有:"number"、"string"、"boolean"、"object"、"function" 和 "undefined"。 如: alert(typeof (123));//typeof(123)返回"number" alert(typeof 阅读全文
posted @ 2011-01-28 19:07 fumen 阅读(207) 评论(0) 推荐(0) 编辑