var x = 1,y = z = 0;
function add(n){
return n = n + 1;
}
y = add(x);
function add(n){
return n = n + 3;
}
z = add(x);
//x = 1,y = z = 4; 複製代碼
//1).
function foo(x){
console.log(arguments);
return x;
}
foo(1,2,3,4,5)
//2).
function foo(x){
console.log(arguments);
return x;
}(1,2,3,4,5)
//不執行,可是不報錯
//3).
(function foo(x){
console.log(arguments);
return x;
}(1,2,3,4,5))
//4).
function foo(){
bar.apply(null,arguments);
}
function bar(x){
console.log(arguments);
}
foo(1,2,3,4,5)複製代碼
parseInt(3,8);//3
parseInt(3,2);//NaN
parseInt(3,0);//3或者NaN或者報錯
//parseInt()第二位參數是之後面的數字爲基底,轉換成10進制複製代碼
string number boolean object undefined function
javascript
function b(x, y, z){
arguments[2] = 10;
alert(a);
}
b(1, 2, 3);
若是函數體改爲下面,結果又會是什麼?
a = 10;
alert(arguments[2]);
//映射關係複製代碼
var f =(
function f(){
return '1';
},
function g(){
return 2;
}
)();
typeof f;//number
//* , 逗號運算符返回第二個值複製代碼
A.undefined == null;//true
B.undefined === null;
C.isNaN('100'); //true
D.parseInt('1a') == 1 //true複製代碼
var foo = '123';
function print(){
var foo = '456';
this.foo = '789';
console.log(foo);
// console.log(this)-->window
}
print();複製代碼
var foo = 123;
function print(){
this.foo = 234;//指向window
console.log(foo);
}
//print();//234
//new print();//123複製代碼
var a = 5;
function test(){
a = 0;
alert(a);
alert(this.a);
var a;
alert(a);
}
// test();//0 5 0
new test();//0 undefined 0複製代碼
function print(){
console.log(foo);//undefined
var foo = 2;
console.log(foo);//2
console.log(hello);//報錯 hello is not defined
}
print();複製代碼
function print(){
var test;
test();
function test(){
console.log(1);
}
}
print();//1複製代碼
function print(){
var x = 1;
if(x == '1') console.log('One');
if(x === '1') console.log('Two');
}
print();//One複製代碼
function print(){
var marty = {
name:'marty',
printName:function(){
console.log(this.name);//marty
}
}
var test1 = {name:'test1'};
var test2 = {name:'test2'};
var test3 = {name:'test3'};
test3.printName = marty.printName;
// var printName2 = marty.printName.bind({name:123});
marty.printName.call(test1);//test1
marty.printName.apply(test2);//test2
marty.printName();//marty
// printName2();//
test3.printName();//test3
}
print();複製代碼
var bar = {a:'002'};
function print(){
bar.a = 'a';
Object.prototype.b = 'b';
return function inner(){
console.log(bar.a);
console.log(bar.b);
}
}
print()();//a,b複製代碼