JavaScript Output defines the ways to display the output of a given code. The output can be displayed by using four different ways which are listed below:
1. innerHTML: It is used to access an element. It defines the HTML content.
Syntax:
document.getElementById("id").innerHTML;
Example: This example uses innerHTML to display the data.
html
<!DOCTYPE html>
< html lang = "en" >
< head >
< title >JavaScript Output</ title >
</ head >
< body >
< h1 >GeeksforGeeks</ h1 >
< h2 >
JavaScript Display Possibilities
Using innerHTML
</ h2 >
< p id = "GFG" ></ p >
< script >
document.getElementById("GFG").innerHTML
= 10 * 2;
</ script >
</ body >
</ html >
|
Output:

2. document.write(): It is used for testing purpose.
Syntax:
document.write()
Example: This example uses document.write() property to display data.
html
<!DOCTYPE html>
< html lang = "en" >
< head >
< title >JavaScript Output</ title >
</ head >
< body >
< h1 >GeeksforGeeks</ h1 >
< h2 >
JavaScript Display Possibilities
Using document.write()
</ h2 >
< p id = "GFG" ></ p >
< script >
document.write(10 * 2);
</ script >
</ body >
</ html >
|
Output:

3. window.alert(): It displays the content using an alert box.
Syntax:
window.alert()
Example: This example uses window.alert() property to display data.
html
<!DOCTYPE html>
< html lang = "en" >
< head >
< title >JavaScript Output</ title >
</ head >
< body >
< h1 >GeeksforGeeks</ h1 >
< h2 >
JavaScript Display Possibilities
Using window.alert()
</ h2 >
< p id = "GFG" ></ p >
< script >
window.alert(10 * 2);
</ script >
</ body >
</ html >
|
Output:

4. console.log(): It is used for debugging purposes.
Syntax:
console.log()
Example: This example uses the console.log() property to display data.
html
<!DOCTYPE html>
< html lang = "en" >
< head >
< title >JavaScript Output</ title >
</ head >
< body >
< h1 >GeeksforGeeks</ h1 >
< h2 >
JavaScript Display Possibilities
Using console.log()
</ h2 >
< p id = "GFG" ></ p >
< script >
console.log(10 * 2);
</ script >
</ body >
</ html >
|
Output:
5. window.prompt() :- it Allows to take input from user
syntax :
window.prompt()
HTML
<!DOCTYPE html>
< html lang = "en" >
< head >
< title >JavaScript Output</ title >
</ head >
< body >
< h1 >GeeksforGeeks</ h1 >
< h2 >
JavaScript Display Possibilities
Using window.alert()
</ h2 >
< p id = "GFG" ></ p >
< script >
window.prompt("Please Enter your Input");
</ script >
</ body >
</ html >
|
Output
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!