Michael
Michael

Reputation: 10303

Can I use node.js as a REPL shell?

This is a noob question.

I am trying to use node.js as a JavaScript REPL (read-evaluate-print loop) shell to work with JavaScript interactively. Unfortunately I can define neither variables nor functions.

> var x = 'abc'
undefined
> function f() {}
undefined
>

What can I do to use node.js as a REPL shell?

P.S. I know I can probably use Rhino Shell but I would prefer node.

Upvotes: 3

Views: 353

Answers (1)

ThiefMaster
ThiefMaster

Reputation: 318568

You can do so. However, those expressions do not have a return value so node prints undefined.

> var x = 'abc'
undefined
> function f() {}
undefined
> f
[Function: f]
> x
'abc'
>

Upvotes: 8

Related Questions