MCQ Hive stays free thanks to ads. Please disable your ad blocker for this site so content and features keep working.
Web Development
JavaScript
Beginner
Q
What is the difference between innerHTML and textContent?
AtextContent parses HTML
BinnerHTML parses its value as HTML (an XSS risk with untrusted data); textContent treats it as plain text
CinnerHTML escapes all tags
DThey are identical
Correct Answer:
B. innerHTML parses its value as HTML (an XSS risk with untrusted data); textContent treats it as plain text
Explanation:
Use textContent for user-supplied data.
ALSO KNOW (related points):
• What is the difference between event.preventDefault() and event.stopPropagation()? → preventDefault stops the browser's default action (such as following a link); stopPropagation stops the event bubbling to ancestor elements
• What is the difference between the DOMContentLoaded and load events? → DOMContentLoaded fires when the HTML is parsed; load waits for all resources, such as images and stylesheets
• What is TypeScript? → A typed superset of JavaScript that compiles (transpiles) to plain JavaScript
• What is the reliable way to test whether a value x is NaN? → Number.isNaN(x)