var y = 1, x = y = typeof x;
x;
複製代碼
var y = 1, x = y = typeof x;
x;//undefined
var y;
var x;
typeof x = undefined;
y = 1;
y = undefined;
x = undefined;
複製代碼
(function f(f){
return typeof f();
})(function(){ return 1; });
複製代碼
(function f(f){//f=>function(){ return 1; }
return typeof f(); //執行f() return 1
})(function(){ return 1; });
//number
(function f(f){
return typeof f;
})(function(){ return 1; });
//function
複製代碼
var foo = {
bar: function() { return this.baz; },
baz: 1
};
(function(){
return typeof arguments[0]();
})(foo.bar);
複製代碼
var foo = {
bar: function() { return this.baz; },
baz: 1
};
(function(){
return typeof arguments[0]();//此題原文解釋爲this指向了window,但我在全局設置了baz的值返回依然是undefined,望大佬能給完美的解釋。
})(foo.bar);
//undefined
複製代碼
var foo = {
bar: function(){ return this.baz; },
baz: 1
}
typeof (f = foo.bar)();//undefined,this指向window
複製代碼
var f = (
function f(){ return "1"; },
function g(){ return 2; })();
typeof f;//"number"...f輸出2
複製代碼
var x = 1;
if (function f(){}) {
x += typeof f;
}
x;//"1undefined",先是1,x=1,而後f不存在undefined
複製代碼
(function(foo){
return typeof foo.bar;
})({ foo: { bar: 1 } }); //undefined ,foo = > {foo:{bar:1}}沒有bar屬性
複製代碼
var length = 10;
function fn() {
console.log(this.length);
}
var obj = {
length: 5,
method: function(fn) {
fn();
arguments[0]();
}
};
obj.method(fn, 1); //10 2
複製代碼
function fn(a) {
console.log(a);
var a = 2;
function a() {}
console.log(a);
}
fn(1);//function a(){} 2,函數先於變量
複製代碼
var f = true;
if (f === true) {
var a = 10;
}
function fn() {
var b = 20;
c = 30;
}
fn();
console.log(a);
console.log(b);
console.log(c); //10 報錯 30
複製代碼
var a = 10;
a.pro = 10;
console.log(a.pro + a);//NaN
var s = 'hello';
s.pro = 'world';
console.log(s.pro + s);//undefinedhello
複製代碼
一些問基礎答題segmentfault