Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 372
Michael Avatar asked May 19 '26 12:05

Michael


1 Answers

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'
>
like image 182
ThiefMaster Avatar answered May 22 '26 01:05

ThiefMaster



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!