亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

一個js面試題

一個js面試題

慕哥9229398 2018-08-01 17:05:19
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
查看完整描述

3 回答

?
largeQ

TA貢獻2039條經驗 獲得超8個贊

.......你的變量是局部變量,你convert 函數沒有返回,funny中的s 變量,并沒有被改變,當然還是hi了。。

查看完整回答
反對 回復 2018-08-04
?
慕無忌1623718

TA貢獻1744條經驗 獲得超4個贊

傳入convert()的s是值傳遞,并不會修改funny()中的s的值。所以在退出convert()不變.

查看完整回答
反對 回復 2018-08-04
?
狐的傳說

TA貢獻1804條經驗 獲得超3個贊

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


查看完整回答
反對 回復 2018-08-04
  • 3 回答
  • 0 關注
  • 1214 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號