Search code examples
javascriptbrowser-console

Is there any way to manually produce an answer in a browser using JavaScript?


So I'm not 100% if the thing I'm asking for is called answer. If you open your browser's console, in any chromium-based browser it should look something like this: enter image description here

And in Firefox it looks something like this: enter image description here

It's the thing that the console writes to if you use something like document.getElementById.

Is there any way to write to said result/answer?


Solution

  • The arrow to the left is the console telling you that some function returned some value.

    If you paste this code to the console, and then run it by typing foo() and pressing enter:

    function foo() {
       return "bar"
    }
    

    It will return the string "Bar", and the icon you mentioned will appear, indicating that some function simply returned a value and did nothing with it.

    Edit: As others mentioned, if you use it with console.log("foo"), the arrow will appear with undefined because the function console.log() doesnt return anything, it explicity prints on the browser's console, but doesn't return any value. Any function that doesn't return a value, the console will return back that arrow with undefined.

    Edit2: A full reference of what you can do with console is here: W3Schools Console Object