JS问题集锦
['1', '2', '3'].map(parseInt)
[1, NaN, NaN]
[typeof null, null of Object]
typeof null === 'Object'
[Object, false]
[3, 2, 1].reduce(Math.pow)
array.reduce(callback, initialValue)
9
var val = 'msg'; console.log('Value is' + (val === 'msg')? 'something':'nothing')
something
var name = 'World!';
(function () {
if (typeof name === 'undefined') {
var name = 'Jack';
console.log('Goodbye ' + name);
} else {
console.log('Hello ' + name);
}
})();
Goodbye Jack
var ary = [0,1,2];
ary[10] = 10;
ary.filter(function(x) { return x === undefined;});
[]
switch()是严格比较
注意String 实例 和 字符串是不一样的
var s1 = 'foo'
var s2 = new String('foo')
console.log(s1 === s2)
false