What are the pure input/output methods in Javascript?
In Webstorm, If a pure JavaScript file is written without HTML, the functions prompt() and alert() cannot be used for input-output. Webstorm gives the error "ReferenceError: is not defined".What are the pure input/output methods in Javascript without HTML
Please sign in to leave a comment.
the only way to run Javascript without HTML is using Node.js interpreter. window.prompt() and window.alert() are functions that web browsers implement, there are no such functions in Node.js - thus the ReferenceError exceptions.
In terms of input and output, the low-level Readline (https://nodejs.org/dist/latest-v8.x/docs/api/readline.html) Node.js module could be used to prompt the user and request input. But you can also try Inquirer (https://www.npmjs.com/package/inquirer) or Prompt (https://github.com/flatiron/prompt)
To write messages to stdout, console.log() is the simplest native solution (available in both browser and Node.js contexts)