<html>
<head>
<meta charset="utf-8">
<title>猎上网面试练习题</title>
</head>
<body>
<pre class="que">[] == ![];</pre>
<pre class="ans">
true
</pre>
<table class="step">
<tr>
<td></td>
<td>[]</td>
<td>==</td>
<td>!Boolean([]);</td>
<td>逻辑运算需进行数据类型转换</td>
</tr>
<tr>
<td></td>
<td>[]</td>
<td>==</td>
<td>!true</td>
<td>0 NaN '' null undefined 在boolean中会变成false 其他为true</td>
</tr>
<tr>
<td></td>
<td>[]</td>
<td>==</td>
<td>false;</td>
<td></td>
</tr>
<tr>
<td></td>
<td>[]</td>
<td>==</td>
<td>0;</td>
<td>如果其中一项为bool值,另外一项不是,则将其转换成数字</td>
</tr>
<tr>
<td></td>
<td>toPrimitive([])</td>
<td>==</td>
<td>0;</td>
<td>如果一项为对象,另一项为数字或字符串,则尝试将对象转换成primitiveValue原始值</td>
</tr>
<tr>
<td></td>
<td>[].valueOf()</td>
<td>==</td>
<td>0;</td>
<td>首先尝试调用 valueOf 得到自身 仍然是对象类型</td>
</tr>
<tr>
<td></td>
<td>[]</td>
<td>==</td>
<td>0;</td>
<td></td>
</tr>
<tr>
<td></td>
<td>[].toString()</td>
<td>==</td>
<td>0;</td>
<td>再尝试调用 toString </td>
</tr>
<tr>
<td></td>
<td>''</td>
<td>==</td>
<td>0;</td>
<td>Array.toString返回一个字符串,使用逗号连接数组中所有元素</td>
</tr>
<tr>
<td></td>
<td>0</td>
<td>==</td>
<td>0</td>
<td>字符串和数值进行比较时,将字符串转换成数值</td>
</tr>
<tr>
<td></td>
<td>0</td>
<td>===</td>
<td>0</td>
<td>两边数据类型一致时,执行严格等运算</td>
</tr>
<tr>
<td></td>
<td></td>
<td>true</td>
<td></td>
<td>得到结果true</td>
</tr>
</table>
<pre class="que"><br/>var a = function( k ) { return false; };
a() && [] == ![];
</pre>
<pre class="ans">
false
</pre>
<pre class="que"><br/>var k = true;
var a = function( k ){
var k = k && true;
return k;
};
a() && [] == ![];
</pre>
<pre class="ans">
undefined
</pre>
<pre class="que"><br/>var k = true;
var a = function( k ){
var k = k && true;
return k;
};
<label style="color:red">在这个区域输入什么代码,使其下列输出正常值</label>
a() && [] == ![];
</pre>
<pre class="ans">
a=function(){return k};
</pre>
<pre class="que"><br/>var arr = [ 1, 2 ];
arr.b = "123";
arr.toString();
</pre>
<pre class="ans">
'1,2'
</pre>
<pre class="que"><br/>var o = {
a : 2,
b : function(){
this.a = 3;
(function(){
alert( this.a ); // 输出==>
this.a = 4;
})();
alert( this.a ); // 输出==>
return { d : o.a + 3 };
}
};
o.b();
o.b.d;
</pre>
<pre class="ans"><br/>
alert undefined,
alert 3,
o.b.d undefined
</pre>
<pre class="que"><br/>var i = 1, j = m = 0;
function a ( k ){
return k = k + 1;
}
j = a( i );
function a ( k ){
return k = k + 3;
}
m = a ( i );
j
m
</pre>
<pre class="ans"><br/>
j 4
m 4
</pre>
<pre class="que"><br/>alert( typeof a);
function a(){
alert( "a.function" );
}
var a = "a.string";
alert( a );
</pre>
<pre class="ans"><br/>
alert function
alert a.string
</pre>
<pre class="que"><br/>var o = {
a : function(){
alert ( this.c );
},
c : " Hunteron "
};
( f = o.a )();
</pre>
<pre class="ans"><br/>
alert undefined
</pre>
</body>
</html>
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |