Why does require('underscore') return undefined when executed at the node.js REPL?

前端 未结 1 1405
你的背包
你的背包 2021-01-01 22:12

When I run node in my console and type var _ = require(\'underscore\');, _ ends up undefined. If I put the same code in a file and execute it, the

1条回答
  •  时光取名叫无心
    2021-01-01 22:59

    The Node repl binds _ to the value of the last evaluated input; which overwrites your _ binding in var _ = ...;. Also see the node.js documentation on the repl.

    This is true no matter what replaces ..., for example:

    $ node
    > var _ = "any value";
    undefined
    > _
    undefined
    

    0 讨论(0)
提交回复
热议问题