Five Ways to Display JavaScript Code
-
console.log:
The
console.log() method is used to display
messages or variables in the browser's console, accessible via
Developer Tools (DevTools).
-
Alert Box:
The
alert() method shows a message in a modal
dialog box, requiring user action before proceeding.
-
Document Write:
The
document.write() method writes directly to the
HTML document. However, it’s not recommended for modern web
development as it can overwrite the entire page.
-
DOM Manipulation:
You can modify an element’s content using JavaScript by
selecting it with
getElementById() and updating its
innerHTML.
-
Browser Console in HTML:
JavaScript output can also be displayed in the browser’s console
by linking a function to an event, such as
onload in the <body> tag.