0

Node version v5.4.1 and I installed lodash in current directory's node_modules. And I encouter this issue where '_' seems special.

> var _ = require('lodash');
undefined
> _.defaults
TypeError: Cannot read property 'defaults' of undefined
    at repl:1:2
    at REPLServer.defaultEval (repl.js:252:27)
    at bound (domain.js:287:14)
    at REPLServer.runBound [as eval] (domain.js:300:12)
    at REPLServer.<anonymous> (repl.js:417:12)
    at emitOne (events.js:82:20)
    at REPLServer.emit (events.js:169:7)
    at REPLServer.Interface._onLine (readline.js:210:10)
    at REPLServer.Interface._line (readline.js:549:8)
    at REPLServer.Interface._ttyWrite (readline.js:826:14)
> var l = require('lodash');
undefined
> l.defaults
[Function]
>

I saw a question related to undefined output. But no question yet cares about the failure of 'require' when '_' as variable name. Do you know any about it?

1 Answer 1

1

The underscore is a special variable that holds the result of the most recent expression. Prior to node v6.0.0, this behavior could not be disabled. However, node v6.0.0 introduced a change that allowed the underscore variable to be overwritten. So you will need to upgrade your copy of node if you want to reassign the _ variable in the node REPL.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.