Javascript 为什么在控制台中显示以下方法,但最后不使用console.log?

Javascript 为什么在控制台中显示以下方法,但最后不使用console.log?,javascript,Javascript,嗨,我想知道为什么我在不使用console.logjakubpresentation的情况下设置以下变量时,我仍然可以看到它 var jakubpresentations = jakub.presentation("formal", " morning "); var jakub = { name: "jakub", surname: "klos", age: 18, profession: "designer", presentation: function(style,

嗨,我想知道为什么我在不使用console.logjakubpresentation的情况下设置以下变量时,我仍然可以看到它

var jakubpresentations = jakub.presentation("formal", " morning ");

var jakub = {
  name: "jakub",
  surname: "klos",
  age: 18,
  profession: "designer",
  presentation: function(style, timeOfDay) {

    if (style === "formal") {
      console.log("good " + timeOfDay + this.name + " Welcome in DesignUX Company")
    } else if (style === "nonformal") {
      console.log("Hi" + this.name + "Welcome in DesignUX Company");
    }
  }
}

var justyna = {
  name: "justyna",
  surname: "rybicka",
  age: 28
}

var jakubpresentations = jakub.presentation("formal", " morning ");
将jakubPresentation的值设置为从函数jakub.presentation返回的值

将变量设置为函数调用时,函数将运行。整个函数将执行。console.log语句位于您运行的函数内

presentation: function(style, timeOfDay) {
  if (style === "formal") {
    console.log("good " + timeOfDay + this.name + " Welcome in DesignUX Company")
  } else if (style === "nonformal") {
    console.log("Hi" + this.name + "Welcome in DesignUX Company");
  }
}

可以通过使用函数创建变量来运行函数。您不必为它提供自己的完整产品线。

因为这正是控制台的功能。它打印最后执行的语句的值。基本上每个控制台都做什么,是的。因为赋值是JavaScript中的一个表达式,它的值就是被赋值的值。
presentation: function(style, timeOfDay) {
  if (style === "formal") {
    console.log("good " + timeOfDay + this.name + " Welcome in DesignUX Company")
  } else if (style === "nonformal") {
    console.log("Hi" + this.name + "Welcome in DesignUX Company");
  }
}