您的位置:首页 > Web前端 > JavaScript

一些javascript题目

2011-08-12 09:15 337 查看
var
result =[10] +1;
console.log(result)
show sourceview sourceprint?

"101"
存在运算符
"+"
,意味着将[10]转化为一个值,相当于调用其valueOf()方法,而Array的valueOf相当于其toString
var
result =[
'a'
,
'b'
,
'c'
] +
""
;
console.log(result)
show sourceview sourceprint?

"a,b,c"
与一个空字符相加,我们大可以就当成强行调用其toString方法,而Array的toString方法相当于调用其join方法,join的默认分隔符则为
","
var
result =
'a'
+ 5;
console.log(result)
show sourceview sourceprint?

"a5"
加号表达式优先考虑字符串拼接
var
result =3.75 | 0;
console.log(result)
show sourceview sourceprint?

3
数值|0相当于对数值进行Math.floor
var
result =65 / 
'a'
;
console.log(result)
show sourceview sourceprint?

NaN
'a'
首先要转换为一个Number类型,既然不能转换为一个正常的数字,就转换为NaN,与NaN进行运算结果都为NaN
var
obj = {
"10"
: 1};
obj[10] = 2;
obj[[1,0]] = 3;
var
result =obj[
"10"
] +obj[10] +obj[[1,0]];
console.log(result)
show sourceview sourceprint?

7
对象的键总为字符串,因此obj[10]相当于obj[
"10"
],obj[[1,0]]相当于obj[
"1,0"
]
var
$ = {
""
: String};
var
result =!!$[([])]();
console.log(result)
show sourceview sourceprint?

false
转换过程如下
!!$[([])]() -->!!$[
""
]() -->!!String() -->!!
""
-->
false
var
result =(
' \t\r\n '
== 0);
console.log(result)
show sourceview sourceprint?

true
考空白字符串的类型
参见http:
//www.cnblogs.com/rubylouvre/archive/2009/09/18/1568794.html这里的回复讨论
var
a =
new
String(
"123"
);
var
b =
"123"
;
var
result =(a === b);
console.log(result)
show sourceview sourceprint?

false
一个为object一个为string
var
a ={key: 1};
var
b ={key: 1};
var
result =(a == b);
console.log(result)
show sourceview sourceprint?

false
两个对象总是不等的
http://blog.vjeux.com/2009/javascript/smallhash-information-compression.html
if ($ != jQuery) {
$ = jQuery.noConflict();
}
var isLogined = true;
var cb_blogId = 57731;
var cb_entryId = 1857951;
var cb_blogApp = "rubylouvre";
var cb_blogUserGuid = "2e47a4b1-de3e-de11-9510-001cf0cd104b";
var cb_entryCreatedDate = '2010/10/2310:04:00';

标签: javascript
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: