Print Log to Javascript Console and Commenting Out Codes

by Didin J. on Dec 06, 2016 Print Log to Javascript Console and Commenting Out Codes

This article show how to Print Log to Javascript Console and Commenting Out Codes.

This is the most usable feature for javascript programming to know and always used everywhere. Print Log to Javascript Console and Commenting Out Codes. Javascript print to console mean display the output to the browser console. Every modern web browser has its own console or developer console. Google Chrome has the Chrome DevTools Console to view logged messages and running Javascript. Firefox has a Web Console which is sub-menu of Web Developer. Safari has a Develop menu that contains the console tab.

Table of contents:

Javascript Console Log

In every programming language always be log output that prints to screen. For example in Java, we can print something to console with code "System.out.println('Hello World')". Javascript have something similar too, it has the feature to display messages or log to the browser console.

Example, we're trying to print something that will display in the browser console. First, open the HTML file that included javascript like this, copy and paste below code to console.html.

<html>
   <head><title>Print Console</title></head>
   <body>
      <script>
         console.log("Hello Javascript");
      </script>
   </body>
</html>

Then open console.html on the browser (e.g. chrome),  right-click on the browser and click inspect.

Click console from inspecting tab, you will see console print out of "Hello Javascript").

 

Commenting out code in Javascript

Sometimes we need to unuse some lines of code or we want to make few line document that explaining the code itself, so we have to comment out code inside the code editor. In javascript, we can be commenting out using slash with start and start with slash "/*  */" or just double slash "//".

Slash with start and vice versa "/* */" is used for many lines of code that will be commenting out.

Double slash is used for commenting out one line only

This is it for now.

That just the basic. If you need more deep learning about HTML, CSS, Javascript or related you can take the following cheap course:

Thank You.

Loading…