Basic Input/output

In JavaScript, you can use the prompt() and console.log() methods for basic input/output.

The prompt() method displays a dialog box with a message for the user to input data. The user's response is stored in a variable that you can use later in your program.

Here's an example of how to use prompt() to get a user's name and then display a personalized greeting:

let name = prompt("What is your name?");
console.log("Hello, " + name + "!");

The console.log() method is used to output data to the console. You can pass any type of data to console.log() and it will be displayed in the console. Here's an example:

javascriptCopy codelet x = 5;
console.log("The value of x is " + x);

This will output "The value of x is 5" to the console.

Last updated