Advanced Input/output
There are other ways for input/output in JavaScript besides prompt
and console.log
. Here are a few examples:
Reading from a file: You can read input from a file using the built-in
fs
module in Node.js. Here's an example:
Writing to a file: You can write output to a file using the
fs
module as well. Here's an example:
Using HTML forms: If you're working with JavaScript in a web environment, you can use HTML forms to get input from users and display output to them. Here's an example:
This example uses an HTML form to get the user's name, and a JavaScript function to display a greeting message to them. The output is displayed in a <p>
element with the ID "output".
Last updated