Single line comments only comment on the used line. Double slash
// is used to create the single-line comment and from the position
Single Line Inline Comments
We can use the single-line comment as an inline comment in the single line. An inline comment is a comment which is added to the code line where the code will be executed but the comment will not execute. From the start of the inline comment to the end of the line will be a comment. But from the start of the line to the start of the inline comment will be a code line that will be executed.
var age = 12; // This is single line inline comment and the new variable age will be created var new_age = age + 20; // This single line inline comment will not affect to sum of age with 20
Multi-line comments can be used to put more comments or explanations about the code. Multi-line comments also used to provide more details about the function, classes, etc. In order to create a multi-line comment, we should set the start and end of the multiline comment.
/* is used to set the start f the multi-line comment and
*/ is used to set the end of the multi-line comment. Between
*/ are interpreted as a comment.
/* This is Multi line comment */ alert("Test"); /* This is Multi-line Comment Too */
Prevent Code Execution with Single Line Comments
alert() function to print screen
Hi which is done by the single-line comment. We can enable this code line just by uncommenting the code line.
Prevent Code Execution with Multi-Line Comments
We can also use multi-line comments in order to prevent some code from execution. This can be useful for more complex test scenarios. In the following example, we will comment on multiple line codes to prevent the execution.
/* alert("Hi"); callThisFunction(); */ alert("Merhaba"); callThatFunction();
In this example the
callThatFunction() will be executed properly where
callThisFunction() will not executed because they are commented or just comments.