Five Ways to Display JavaScript Code

  1. console.log: The console.log() method is used to display messages or variables in the browser's console, accessible via Developer Tools (DevTools).
  2. Alert Box: The alert() method shows a message in a modal dialog box, requiring user action before proceeding.
  3. 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.
  4. DOM Manipulation: You can modify an element’s content using JavaScript by selecting it with getElementById() and updating its innerHTML.
  5. 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.