Q1. What is console.log() in JavaScript?
console.log() is used to display output inside the browser's console. It is mainly used for debugging and testing code.
Example
Output
Displayed in the browser console:
Developers use this method to check variable values and program execution.
Example
console.log("Hello JavaScript");Output
Displayed in the browser console:
Hello JavaScriptDevelopers use this method to check variable values and program execution.
Q2. What is document.write() in JavaScript?
document.write() is used to display output directly on the web page.
Example
Output
The text appers on the webpage.
Example
document.write("Welcome to JavaScript");Output
The text appers on the webpage.
Important Note:
It should not be used after the page is fully loaded.
It can overwrite the entrie page content.
Q3. What is innerHTML in JavaScript?
innerHTML is used to change or display HTML content inside an element.
Example
This updates the content inside the element with the given ID. It is widely used for dynamic web content.
Example
document.getElementById("demo").innerHTML = "Hello User";This updates the content inside the element with the given ID. It is widely used for dynamic web content.
