CRT-600 practice question 2 of 30

A developer has the function, shown below, that is called when a page loads. function onload() { console.log(“Page has loaded!”); } Where can the developer see the log statement after loading the page in the browser?

Full set: 223 questions
Answer options
A: Terminal running the web server.
B: Browser performance toots
C: Browser javaScript console Correct answer
D: On the webpage.
Correct Answer:
C. Browser javaScript console
Explanation

The console.log() function is a client-side JavaScript method used for debugging. It writes a message to the web console, which is a standard feature within the developer tools of modern web browsers. When the onload function executes in the browser, the string "Page has loaded!" is sent specifically to this console interface, not to the server, the performance profiler, or the visible webpage content. This tool is fundamental for developers to inspect code execution and variable states.

Why Incorrect

A. Terminal running the web server. This displays server-side logs. The provided JavaScript code runs on the client's browser, completely separate from the server's terminal environment.
B. Browser performance tools. These tools are for analyzing runtime performance, memory usage, and rendering speed. They do not display messages from console.log().
D. On the webpage. Displaying content directly on the webpage requires manipulating the Document Object Model (DOM), for example, using document.write() or setting an element's innerHTML. ---

References

1. MDN Web Docs (Mozilla): The console.log() method outputs a message to the web console. The web console is a tool available in web browsers for logging information

debugging

and interacting with the page's JavaScript context.

Source: MDN Web Docs

"Console: log() method"

Section: "Syntax".

Link: https://developer.mozilla.org/en-US/docs/Web/API/console/log

2. Salesforce Lightning Web Components Developer Guide: The official documentation for developing on the Salesforce platform explicitly instructs developers to use browser developer tools to debug JavaScript. It states

"To check the value of a component property in your browser’s developer tools

use console.log(). Open the browser console to see the output."

Source: Salesforce Lightning Web Components Developer Guide

"Debug Lightning Web Components"

Section: "Debug Your Code".

Link: https://developer.salesforce.com/docs/platform/lwc/guide/debug.html

3. W3C Recommendation: The Console API specification

which standardizes this functionality

defines the log method as a function that "outputs the arguments to the console."

Source: W3C

"Console API"

Section 4.1: "The log function".

Link: https://www.w3.org/TR/console-api/#log

Scroll to Top