编程题

//1、分析下面的JavaScript代码:
function employee(name,code){
    this.name = "laoli";
    this.code = "A001";
}
var newemp = new employee("xiaoli","A002");
document.write("雇员姓名:" + newemp.name + "<br>");
document.write("雇员代号:" + newemp.code + "<br>");
/2、输出结果
function Person(name,age,sex){
    var a=0;
    this.name = name;
    this.age = age;
    this.sex = sex;
    function ss(){
        a++;  
        console.log(a);
    }
    this.say = ss;
}
var oPerson = new Person();
oPerson.say();  //  1 
oPerson.say();  //  2
var oPerson1 = new Person();
oPerson1.say();  //1

3下面的js代码执行完毕后x,y,zd的值分别是多少?
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);   
console.log(x,y,z) // 1,4,4

编程题仅供参考

posted @ 2020-01-11 23:02  巷陌i  阅读(134)  评论(0编辑  收藏  举报