Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
168 views
Welcome To Ask or Share your Answers For Others

1 Answer


    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');

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...