Question1

var foo = function foo() {
console.log(foo === foo);
};
foo();

输出是“true”,因为foo就指代变量foo,两个是相等的。如果改成这样同样成立:

var foo = function() {
console.log(foo === foo);
};
foo();

Question2

function aaa() {
return
{
test: 1
};
}
alert(typeof aaa());

此题初看返回是一个object,但是注意return后面有一个换行,因此程序会如下执行:

function aaa() {
return;
{
test: 1
};
}
alert(typeof aaa());

返回值是undefined。

Question3

Number("1") - 1 == 0;

Number函数可以将非数值转换为数值,Number("1")为1,所以正确。

Question4

(true + false) > 2 + true;

"+"运算符会将值自动转换为number,

true + false = 1

然后变为

1 > 2 + true

“+”优先级大于“>”

1 > 3

因此答案为false。

Question5

function bar() {
return foo;
foo = 10;
function foo() {}
var foo = '11';
}
alert(typeof bar());

函数声明会被提前,因此执行顺序如下:

function bar() {
function foo() {}
return foo;
foo = 10;
var foo = '11';
}
alert(typeof bar());

所以返回的function类型。

Question6

"1" - - "1";

等价于1 - (-1),所以为2.

Question7

var x = 3;

var foo = {
x: 2,
baz: {
x: 1,
bar: function() {
return this.x;
}
}
} var go = foo.baz.bar; alert(go());
alert(foo.baz.bar());

答案是3,1.this指向函数所属的对象。

Question8

new String("This is a string") instanceof String;

3个特殊的引用类型,String,Boolean,Number

Question9

[] + [] + 'foo'.split('');

"+"用在数组上时候,空数组转换为空字符串,非空数组转换为逗号分隔的字符串。

"" + "" +  "f,o,o" = "f,o,o"

Question10

new Array(5).toString();

数组转换为字符串,undefined转换为空字符串,答案是:",,,,"

Question11

var myArr = ['foo', 'bar', 'baz'];
myArr.length = 0;
myArr.push('bin');
console.log(myArr);

['bin']

Question12

String('Hello') === 'Hello';

注意是String函数而不是new String ,所以结果为true

Question13

var x = 0;
function foo() {
x++;
this.x = x;
return foo;
}
var bar = new new foo;
console.log(bar.x);

这个写错了,不是很确定,应该是返回的都是foo是函数,函数是没有x这个属性的。返回undefined,不知对不对。

Question14

"This is a string" instanceof String;

字符串只是基本数据类型,不是对象,也不可能是任何对象实例,结果为 false

Question15

var bar = 1,
foo = {}; foo: {
bar: 2;
baz: ++bar;
};
foo.baz + foo.bar + bar;

foo:{}这种语法在js中称为labeled声明,对于前面定义的空对象foo并没有任何卵影响,所以foo.bar,foo.baz都等于undefined,“+”将其转换为NaN,任何数据加NaN都会返回NaN,所以答案是NaN。

Question16

var myArr = ['foo', 'bar', 'baz'];
myArr[2];
console.log('2' in myArr);

in操作在js中是检测某个属性是否存在于对象中,数组的长度是3,有0,1,2的numeric属性,返回true。

Question17

var arr = [];
arr[0] = 'a';
arr[1] = 'b';
arr.foo = 'c';
alert(arr.length);

数组的长度仅受numeric属性的影响。返回2.

Question18

10 > 9 > 8 === true;

解析:

((10 > 9) > 8) === true;
(true > 8) === true;
(1 > 8) === true;
false === true;
false;

Question19

function foo(a, b) {
arguments[1] = 2;
alert(b);
}
foo(1);

argunments对象仅仅包含传入foo的参数。返回undefined

Question20

NaN === NaN

NaN不与任何值相等,包括NaN本身。注意typeof NaN 返回“number”

参考资料

reddit

最新文章

  1. 进一步丰富和简化表单管理的组件:form.js
  2. 如何部署Iveely.Computing分布式实时计算系统
  3. --Dirring love 音乐(01背包问题)
  4. NPM使用
  5. Maven —— 如何设置HTTP代理
  6. JSF 2 button and commandButton example
  7. 【和我一起学python吧】python入门语法总结
  8. OC2_使用系统协议
  9. hibernate sql查询
  10. Qt新建项目No valid kits found解决思路
  11. Qt学习--部件深入--烤猪蹄
  12. 基于visual Studio2013解决C语言竞赛题之1039移动
  13. BZOJ 4085:[Sdoi2015]quality(round 2 音质检测)(数据结构)
  14. vscode调试html页面,及配置说明
  15. var $this = $(this)是什么意思?
  16. maven中pom文件配置解决资源文件的编码问题
  17. mysql5.7不支持group by的解决办法
  18. /etc/hosts和/etc/hostname区别
  19. PhpStorm 为 Laravel 搭建 PhpUnit 单元测试环境
  20. 盲刷bios

热门文章

  1. Oracle 设置自启动
  2. List接口和Set接口及其常用实现类概述
  3. vue项目中引入mui.poppicker.js文件时报错“Uncaught ReferenceError: mui is not defined”
  4. sql 2008常用语法语句收集
  5. 「树的直径」BFS方法证明
  6. 【Linux】服务器间免密登录、免确认机器指纹
  7. 26 October in 614
  8. 20175120彭宇辰 《Java程序设计》第十周学习总结
  9. ubuntu16.04 常用软件
  10. ceph-cluster map