简体   繁体   English

为什么 VS 没有给我与 DevTools 中的控制台相同的结果?

[英]Why VS doesn't give me the same result as console in DevTools?

I'm sorry if this questions is being raised but I'm really new to coding and started to have the first difficult issue and can't figure it out.如果有人提出这个问题,我很抱歉,但我真的是编码新手,并且开始遇到第一个难题并且无法弄清楚。 I have write a simple code like this because I have to learn the return command:我写了这样一个简单的代码,因为我必须学习return命令:

function multiplyByNineFifths (number) {
    return number *(9/5);
};

function getFahrenheit (celcius) {
    return multiplyByNineFifths (celcius) + 32;
};

getFahrenheit(15);

but when when I want to run the code in VS it says:但是当我想在 VS 中运行代码时,它说:

[Running] node "c:\Users\Oerd Bej\Desktop\JavaScript
exercises\tempCodeRunnerFile.js"
[Done] exited with code=0 in 0.088 seconds`

while in DevTools in console it runs perfectly and it gives me the right answer which is 59.而在控制台的 DevTools 中,它运行完美,它给了我正确的答案,即 59。

Please can you help me to figure it out what should I do, I have installed node.js and all the necessary plug in in VS but dont know what is wrong or what is the right question that I have to ask in order to understand it well.请你能帮我弄清楚我应该怎么做,我已经在 VS 中安装了 node.js 和所有必要的插件,但不知道哪里出了问题,或者我必须问什么是正确的问题才能很好地理解它。 Every error in VS it breaks my heart VS 中的每一个错误都让我心碎

在此处输入图像描述

It's because logging is a little different in Chrome than in Node.这是因为 Chrome 中的日志记录与 Node 中的有些不同。 If you type console.log(3) in Chrome, it will log 3 , and then the return value of console.log which is undefined (because console.log doesn't return anything).如果您在 Chrome 中键入console.log(3) ,它将记录3 ,然后是undefinedconsole.log的返回值(因为console.log不返回任何内容)。 Chrome will always automatically log the function's return value. Chrome 将始终自动记录函数的返回值。 Node doesn't.节点没有。 It will only log 3 .它只会记录3 Node executes the getFahrenheit function, but this function doesn't return anything.节点执行getFahrenheit function,但是这个 function 没有返回任何东西。 It just computes a number in memory, that's it, so nothing gets displayed.它只是计算 memory 中的一个数字,仅此而已,因此不会显示任何内容。 If you want to see the result of this operation you need to log it with console.log(getFahrenheit(15)) .如果您想查看此操作的结果,您需要使用console.log(getFahrenheit(15))记录它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM