猿问

一个js面试题

function convert(s) {

    console.log(s);//hi

    s +=s.toUpperCase();

    console.log(s);//hiHI

}

function funny(s) {

    convert(s);

    console.log(s);//hi

}

funny('hi');//求问为什么第三个是hi吗?为什么不是hiHI


慕斯王
浏览 495回答 1
1回答

慕姐4208626

    function convert(otherStr) {        console.log(otherStr);//hi        otherStr += otherStr.toUpperCase();        console.log(otherStr);//hiHI    }    function funny(str) {        convert(str);        console.log(str);//hi    }    funny('hi');不知道这样是不是能看明白一点另外如果想第三个想输出hiHI可以吧代码改成如下function convert(otherStr) {        console.log(otherStr);//hi        otherStr += otherStr.toUpperCase();        console.log(otherStr);//hiHI        return otherStr    }    function funny(str) {        //用一个变量来接收convert返回的值,当然也可以不接收直接打印出来        var res = convert(str);        console.log(res);//hiHI    }    funny('hi');
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答