How do I get console input in javascript?

2019-01-17 13:58发布

I'm currently using spidermonkey to run my JavaScript code. I'm wondering if there's a function to get input from the console similar to how Python does this:

var = raw_input()  

Or in C++:

std::cin >> var;

I've looked around and all I've found so far is how to get input from the browser using the prompt() and confirm() functions.

2条回答
▲ chillily
3楼-- · 2019-01-17 14:28

In plain JavaScript, simply use response = readline() after printing a prompt.

In Node.js, you'll need to use the readline module: const readline = require('readline')

查看更多
登录 后发表回答