简体   繁体   English

node.js控制台-节点控制台中的“未定义”是什么?

[英]node.js console - What is `undefined` in node console?

I'm novice in javascript. 我是javascript新手。 My knowlegde in scripting languages is python, and we know that it use modules for specific task. 我在脚本语言中的知识点是python,我们知道它使用模块来执行特定任务。 In any python console, we can use 在任何python控制台中,我们都可以使用

import numpy as np

But it do not return anything in the console. 但是它不会在控制台中返回任何内容。 So if i use the "same" thing in a node console i get this 因此,如果我在节点控制台中使用“相同”的东西,我会得到这个

var module = require('module')
undefined

So, i'm wondering what mean that undefined return from node console. 因此,我想知道从节点控制台返回undefined含义是什么。

It's the return value from declaring a variable with var . 这是使用var声明变量的返​​回值。 Since it doesn't return anything, you get undefined . 由于它不返回任何内容,因此您将获得undefined The assignment itself does however return the right-hand-side value, so chaining assignments is possible. 但是,分配本身确实会返回右侧值,因此可以进行链接分配。

undefined表示表达式没有返回值。

Every command in node returns undefined unless you tell it to return something else. 节点中的每个命令都返回undefined,除非您告诉它返回其他内容。 It won't affect anything your program, it is just the default return statement. 它不会影响您的程序,它只是默认的return语句。

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

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