简体   繁体   English

vscode中的Node.js

[英]Node.js in vscode

So I wrote the below using VSCode and executed in the node.js terminal 所以我用VSCode编写了下面的代码,并在node.js终端中执行

let city = "Belgrade," 
let country = "Serbia" 
let location = city + ', ' + country

Apparently nothing works it goes like this. 显然没有任何效果,它像这样。

终端显示

It looks like application worked perfectly well. 看起来应用程序运行良好。 You executed the node interpreter in the shell. 您在外壳中执行了节点解释器。 So, the node engine took over, created 3 variables, then quit. 因此,节点引擎接管了工作,创建了3个变量,然后退出。 Node does not output each statement it runs like a shell script does, so you would not see anything from the console unless you explicitly told it to do so. Node不会输出它运行的每条语句都像Shell脚本一样,因此,除非您明确要求这样做,否则您不会从控制台看到任何内容。 If you want to output to the console, you can simply use the console.log() function or one of its variants (you can find more information https://developer.mozilla.org/en-US/docs/Web/API/Console/log ). 如果要输出到控制台,可以只使用console.log()函数或其变体之一(您可以找到更多信息https://developer.mozilla.org/en-US/docs/Web/API /控制台/日志 )。 So try explicetely outputting your information to the console: 因此,尝试将信息明确输出到控制台:

let city = "Belgrade," let country = "Serbia" let location = city + ', ' + country console.log(location)

Assignment only will not display the results. 仅分配不会显示结果。 You need to print them out for displaying the values in the terminal. 您需要打印出来以在终端中显示值。

console.log(city); 
console.log(country);
console.log(location);

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

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