1.
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, y, z 1,4,4
2.
function foo(x){
console.log(arguments);
return x
}(1,2,3,4,5) //结果不报错,也不显示任何结果
3.
function foo() {
bar.apply(null, arguments);
}
function bar() {
console.log(arguments); //[1, 2, 3]
}
foo(1, 2, 3,);
4.
var x = 1;
if(function f() {
}) {
// function一旦变成表达式,就会被立即执行。
x += typeof f;
// 任何变量未经声明就使用肯定报错,除了typeof
}
console.log(x); // 1undefined
5.问题
str.charCodeAt(i) //求第i位字符串的Unicode编码
var str = "wozuimei 美";
var count = 0;
function myFun(str){
for(var i = 0;i < str.length; i++){
//方法一
// if(str.charCodeAt(i) > 255){ //str.charCodeAt(i) 求字符串的第i位Unicode编码
// count += 2;
// }else{
// count ++;
// }
//方法二 将var count = str.length;
if(str.length > 255){
count ++;