简体   繁体   English

为什么节点不能在我的终端或浏览器中运行javascript函数?

[英]Why doesn't node run javascript functions in my terminal or browser?

I'm using node.js to run JavaScript in my terminal. 我正在使用node.js在终端中运行JavaScript。 When I run the following JavaScript file (testfile.js) in my terminal with the command "node testfile.js", here's what I get: 当我在终端中使用“ node testfile.js”命令运行以下JavaScript文件(testfile.js)时,得到的是:

console.log("meh");

=> meh

So that works fine. 这样就可以了。 But when I make it a function like this: 但是当我使它成为这样的功能时:

function sayMeh() {
    console.log("meh");
};

sayMeh;

=> 

I get no result. 我没有结果。 Why? 为什么? How can I test JS to see if it works? 我如何测试JS是否可以正常工作?

您需要调用函数,而不仅仅是提及它。

sayMeh();

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

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