首页 > 解决方案 > Javascript 函数 - 在文件中调用两个函数

问题描述

问题:两个函数返回不同的数据,但调用两个函数后都接收到最后一个函数的输出。为什么?

javascript

var printStudentInfo = function () {
    return 'Name';
  }

var printStudentTerritory = function () {
    return 'Age';
  }

printStudentInfo();    
printStudentTerritory();

标签: javascript

解决方案


简而言之,这就是printStudentInfo(); printStudentTerritory();建议,let someVariable = printStudentInfo(); printStudentTerritory();因为最后一个函数返回“年龄”。您的变量分配给“年龄”


推荐阅读