JS问题集锦(一)

JS问题集锦

  • ['1', '2', '3'].map(parseInt)
// map(callback(currentValue[, index[, array]][,thisArg]))
// parseInt(string[, radix]) radix表示string是多少进制表示的
// Result
[1, NaN, NaN]
  • [typeof null, null of Object]
typeof null === 'Object' //定义
// instanceof 运算符用来检测 constructor.prototype 是否存在于参数的原型链上。
// Result
[Object, false]
  • [3, 2, 1].reduce(Math.pow)
array.reduce(callback, initialValue)
// Result
9
  • var val = 'msg'; console.log('Value is' + (val === 'msg')? 'something':'nothing')
// 知识点 + 号和 ?的优先级
//Result
something
  • 题目如下
var name = 'World!';
(function () {
    if (typeof name === 'undefined') {
        var name = 'Jack';
        console.log('Goodbye ' + name);
    } else {
        console.log('Hello ' + name);
    }
})();
// 该题目的考点是变量提升即:function 和 variables 的声明会被提升到函数或者全局作用域的顶部
// Result
Goodbye Jack
  • 题目如下
var ary = [0,1,2];
ary[10] = 10;
ary.filter(function(x) { return x === undefined;});
//  从 3 – 9 都是没有初始化的’坑’!, 这些索引并不存在与数组中. 在 array 的函数调用的时候是会跳过这些’坑’的
// Result
[]
  • switch()是严格比较
    注意String 实例 和 字符串是不一样的
var s1 = 'foo'
var s2 = new String('foo')
console.log(s1 === s2)
// Result
false
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值