[英]Why VS doesn't give me the same result as console in DevTools?
如果有人提出这个问题,我很抱歉,但我真的是编码新手,并且开始遇到第一个难题并且无法弄清楚。 我写了这样一个简单的代码,因为我必须学习return
命令:
function multiplyByNineFifths (number) {
return number *(9/5);
};
function getFahrenheit (celcius) {
return multiplyByNineFifths (celcius) + 32;
};
getFahrenheit(15);
但是当我想在 VS 中运行代码时,它说:
[Running] node "c:\Users\Oerd Bej\Desktop\JavaScript
exercises\tempCodeRunnerFile.js"
[Done] exited with code=0 in 0.088 seconds`
而在控制台的 DevTools 中,它运行完美,它给了我正确的答案,即 59。
请你能帮我弄清楚我应该怎么做,我已经在 VS 中安装了 node.js 和所有必要的插件,但不知道哪里出了问题,或者我必须问什么是正确的问题才能很好地理解它。 VS 中的每一个错误都让我心碎
这是因为 Chrome 中的日志记录与 Node 中的有些不同。 如果您在 Chrome 中键入console.log(3)
,它将记录3
,然后是undefined
的console.log
的返回值(因为console.log
不返回任何内容)。 Chrome 将始终自动记录函数的返回值。 节点没有。 它只会记录3
。 节点执行getFahrenheit
function,但是这个 function 没有返回任何东西。 它只是计算 memory 中的一个数字,仅此而已,因此不会显示任何内容。 如果您想查看此操作的结果,您需要使用console.log(getFahrenheit(15))
记录它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.