考试时间:2017-09-02-提前批内推-笔试
1)
测试代码如下:
var a = {};
b = { key: 'b' };
c = { key: 'c' };
a[b] = 123;
a[c] = 456;
console.log(a); //{ '[object Object]': 456 }
console.log(a[b]); //456
a[b]通过索引’[object Object]'获取到对象a的一个属性。之所以结果是456,是因为a[b]
和a[c]
获取到的是同一个属性,a[c]=456
这行代码覆盖了原有属性。
选D
测试代码
(function() {
var a = b = 3;
})();
console.log(typeof a !== 'undefined'); // false
console.log(typeof b !== 'undefined'); // true
var a = b = 3 这段代码是从右往左执行的。先执行b =3 , 由于b在函数内未声明,所以被认为是全局变量,所以可以外部被访问,变量a在函数内被声明,所以在外部访问不到。
选A
console.log(NaN == NaN); //false
console.log(NaN === NaN); //false
console.log(undefined == null); //true
console.log(undefined === null); //false
关于NaN:
NaN compares unequal (via ==, !=, =, and !) to any other value – including to another NaN value.
选C
<!DOCTYPE>
<html>
<head>
<style>
</style>
</head>
<body>
<input id="target" type="text">
<script>
var input = document.getElementById('#target');
target.onmousedown = function() {
console.log('on