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 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 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 it self, so we have to commenting out code inside code editor. In javascript, we can 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 commenting out.

Double slash is used for commenting out one line only

This is it for now.

 

Thank You.

The following resources might be useful for you:

Loading…