-
Hajipur, Bihar, 844101
Hajipur, Bihar, 844101
JS Basics
JS Variables & Operators
JS Data Types & Conversion
JS Numbers & Math
JS Strings
JS Dates
JS Arrays
JS Control Flow
JS Loops & Iteration
JS Functions
JS Functions
Function Definitions
Function Parameters
Function Invocation
Function Call
Function Apply
Function Bind
Function Closures
JS Arrow Function
JS Objects
JS Objects
JS Object Properties
JS Object Methods
JS Object Display
JS Object Constructors
Object Definitions
Object Get / Set
Object Prototypes
Object Protection
JS Classes & Modules
JS Async Programming
JS Advanced
JS Destructuring
JS Bitwise
JS RegExp
JS Precedence
JS Errors
JS Scope
JS Hoisting
JS Strict Mode
JS this Keyword
JS HTML DOM
DOM Intro
DOM Methods
DOM Document
DOM Elements
DOM HTML
DOM Forms
DOM CSS
DOM Animations
DOM Events
DOM Event Listener
DOM Navigation
DOM Nodes
DOM Collections
DOM Node Lists
JS BOM (Browser Object Model)
JS Window
JS Screen
JS Location
JS History
JS Navigator
JS Popup Alert
JS Timing
JS Cookies
Web Storage API
JS Web APIs
JS AJAX
AJAX Intro
AJAX XMLHttp
AJAX Request
AJAX Response
AJAX XML File
AJAX PHP
AJAX ASP
AJAX Database
AJAX Applications
AJAX Examples
JS JSON
JSON Intro
JSON Syntax
JSON vs XML
JSON Data Types
JSON Parse
JSON Stringify
JSON Objects
JSON Arrays
JSON Server
JSON PHP
JSON HTML
JSON JSONP
JS Canvas
JS Graphics & Charts
JS Basics
JS Variables & Operators
JS Data Types & Conversion
JS Numbers & Math
JS Strings
JS Dates
JS Arrays
JS Control Flow
JS Loops & Iteration
JS Functions
JS Functions
Function Definitions
Function Parameters
Function Invocation
Function Call
Function Apply
Function Bind
Function Closures
JS Arrow Function
JS Objects
JS Objects
JS Object Properties
JS Object Methods
JS Object Display
JS Object Constructors
Object Definitions
Object Get / Set
Object Prototypes
Object Protection
JS Classes & Modules
JS Async Programming
JS Advanced
JS Destructuring
JS Bitwise
JS RegExp
JS Precedence
JS Errors
JS Scope
JS Hoisting
JS Strict Mode
JS this Keyword
JS HTML DOM
DOM Intro
DOM Methods
DOM Document
DOM Elements
DOM HTML
DOM Forms
DOM CSS
DOM Animations
DOM Events
DOM Event Listener
DOM Navigation
DOM Nodes
DOM Collections
DOM Node Lists
JS BOM (Browser Object Model)
JS Window
JS Screen
JS Location
JS History
JS Navigator
JS Popup Alert
JS Timing
JS Cookies
Web Storage API
JS Web APIs
JS AJAX
AJAX Intro
AJAX XMLHttp
AJAX Request
AJAX Response
AJAX XML File
AJAX PHP
AJAX ASP
AJAX Database
AJAX Applications
AJAX Examples
JS JSON
JSON Intro
JSON Syntax
JSON vs XML
JSON Data Types
JSON Parse
JSON Stringify
JSON Objects
JSON Arrays
JSON Server
JSON PHP
JSON HTML
JSON JSONP
JS Canvas
JS Graphics & Charts
JavaScript provides multiple ways to output or display data to users or developers. Each method is used in different situations depending on your needs.
innerHTML
The innerHTML
property sets or returns the HTML content of an element.
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = "Hello, this is innerHTML!";
</script>
🧠 Best For: Displaying content in the web page dynamically.
document.write()
The document.write()
method writes content directly into the HTML document.
Warning: It overwrites the entire page if used after the page has loaded.
<script>
document.write("This is written using document.write()");
</script>
⚠️ Avoid using it in modern apps, especially after the document is fully loaded.
window.alert()
The alert()
method pops up a dialog box with the specified message.
<script>
alert("Hello! This is an alert box.");
</script>
🧠 Best For: Quick debugging or user notifications.
console.log()
The console.log()
method logs information to the browser console.
<script>
console.log("This is a message in the console.");
</script>
🧠 Best For: Developers — used for debugging code.
Q1. How do you use JavaScript to insert the text "Welcome to my website" into a <p>
element with the id message
using innerHTML
?
Q2. How can you write the message "Page Loaded" directly into the HTML document using document.write()
?
Q3. How do you create a pop-up alert box in JavaScript that says "Please enter your name"?
Q4. How can you print the number 42
in the browser’s console using console.log()
?
Q5. What happens when you use document.write()
after the webpage has fully loaded? Demonstrate with an example.
Q6. How can you use innerHTML
to change the content of a <div>
with id output
to "JS Output Example"?
Q7. How do you show both a console log and an alert for the message "Debugging started"?
Q8. How do you create an HTML page where clicking a button logs "Button clicked!" to the console?
Q9. What is the correct way to display multiple lines using document.write()
?
Q10. How do you insert dynamic content (like a user's name) into an HTML element using innerHTML
?
Q1: Which method is commonly used to write into an HTML element?
Q2: What will document.write("Hello") do if run after the document is loaded?
Q3: Which JavaScript method is used to display a pop-up alert box?
Q4: What is the best method for displaying information to developers during debugging?
Q5: Which output method inserts content into a specific element on the page?
Q6: Which output method displays information in the browser’s developer console?
Q7: Which method is not recommended in modern JavaScript practice?
Q8: What is the correct syntax for writing a console log?
Q9: Which of the following outputs a string on the webpage itself?
Q10: What type of message is suitable to show using alert()?