Web Analytics Made Easy -
StatCounter console.log() - CodingForum

Announcement

Collapse
No announcement yet.

console.log()

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • console.log()

    I am using Linux Mint 20 and the Firefox browser 78.0.2
    I'm still trying to learn as much as i can about JavaScript ES6 so i thought i'd give console.log a go. But when i press Ctrl + Shift + K the console opens up
    so i type: var name = "Henry"; (then i press Enter to go to a new line but am rewarded with the output of 'undefined'. When i then type console.log(name); the output is then:
    Henry
    udefined
    Is there a tutorial out there that could help me?
    Could someone tell me what i'm doing wrong please.
    Thanks in advance

  • #2
    Originally posted by col67nt591 View Post
    I am using Linux Mint 20 and the Firefox browser 78.0.2
    I'm still trying to learn as much as i can about JavaScript ES6 so i thought i'd give console.log a go. But when i press
    Code:
    Ctrl + Shift + K
    the console opens up
    so i type:
    Code:
    var name = "Henry";
    (then i press Enter to go to a new line but am rewarded with the output of 'undefined'. When i then type
    Code:
    console.log(name); the output is then:
    Henry
    udefined
    Is there a tutorial out there that could help me?
    Could someone tell me what i'm doing wrong please.
    Thanks in advance
    This is my revised post. Sorry for previous errors.

    Comment


    • #3
      I must admit that I’ve never used the console to actually execute some code. Can’t you just create a simple HTML file in your code editor and load it in your browser to test your JS? That’s what I’m usually doing and it has been working great for me.
      Stop solving problems you don’t yet have!

      Comment


      • #4
        The undefined you see is the return value of the statement (or line) and is indicated by an arrow.
        The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
        André Behrens, NY Times Software Developer

        Comment


        • #5
          I agree with 'Dormilich'. The undefined message is just interpretation of the 'Return' on the keyboard.

          I also agree with VIPStephan. Just create a small HTML file and save locally. Try using an alert('test') somewhere in the code and see that the line is executed. Then replace with console.log('test') and the information is no longer in a pop-up alert message, but is sent to the console.log. Make sure that you are in the console by clicking the button at the top (as opposed to the 'Debugger' or other options near the top of the display).

          Also, I typically show the console log contents by pressing CTRL-Shift-J instead of K or alternatively pressing F12 after starting the program.

          Here is a very simple demonstration:
          Code:
          <!DOCTYPE html><html lang="en"><head><title> Test Page </title>
          <meta charset="UTF-8">
          <meta name="viewport" content="width=device-width,initial-scale=1.0, user-scalable=yes"/>
          <!-- link rel="stylesheet" href="common.css" media="screen" -->
          </head><body>
          
          <h3> Sample output as an alert and console.log</h3>
          <pre id='demo'></pre>
          
          <script>
          console.clear();
          alert('test');
          console.log('test');
          
          document.getElementById('demo').innerHTML = 'test';
          </script>
          
          </body></html>
          Last edited by jmrker; Jul 29, 2020, 12:09 PM. Reason: Corrected typo in <meta> tag

          Comment


          • #6
            Think i'll do as VIPStephan suggested. Thanks all for taking the time out to reply.

            Comment

            Working...
            X