为了账号安全,请及时绑定邮箱和手机立即绑定

一个js面试题

一个js面试题

慕斯王 2018-11-13 12:15:50
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
查看完整描述

1 回答

?
慕姐4208626

TA贡献1852条经验 获得超7个赞


    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-12-09
  • 1 回答
  • 0 关注
  • 494 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号