JavaScript user input in console

I need to get user input when running .js in the console with spidermonkey as follows:

$ js myprogram.js

What is the equivalent of JavaScript Ruby gets ?

+4
source share
2 answers

As far as I know, there is a readline () function, but this is a special function for spidermonkey, it is not part of javascript.

Example:

1) Readline-test.js:

 print("Type some text and press <ENTER>:\t"); var userInput = readline(); print("User input: " + userInput); 

2) js readline-test.js

For more information, see https://developer.mozilla.org/en-US/docs/SpiderMonkey/Introduction_to_the_JavaScript_shell .

+5
source

You cannot depend on which console is there. This is not what is guaranteed, even if most browsers have a javascript console. In addition, I do not believe that you can get values ​​without calling a function from the console.

0
source

All Articles