Javascript Comments

Basically comments are used to include notes or suggestions or warnings to JavaScript code. This can make it easier to read and understand. Comments can also be used to disable code to prevent from execution.

JavaScript supports both C-style and C++-style comments:

  • Text written after // is treated as a comment and is ignored by JavaScript. This is used for a single line comment.
  • Text written between the characters /* and */ is treated as a comment. This may span multiple lines.
  • JavaScript also recognizes the HTML comment opening sequence is not recognized by JavaScript so it should be written as //-->.

Example: Single Line Comments

<html>
<head>
<title>My first Javascript code</title>
</head>
// x = 5 + 6; I will not be executed
<body>
</body>
</html>

Example: Multi Line Comments

<html>
<head>
<title>My first Javascript code</title>
</head>
//Below code will not be executed
/*
This function will used to
calculate add, sub, multiply and div operations. 
*/
function Calculate(a,b,type)
{
var ret_val;
	switch(type)
	{
		case "add":
		ret_val = a + b;
		break;
		case "sub":
		ret_val = a - b;
		break;
		case "mul":
		ret_val = a * b;
		break;case "div":
		ret_val = a / b;
		break;
	}
	return ret_val;
}

<body>
</body>
</html>

See Also

Javascript Built in String Object
Javascript Built in Number Object
Javascript Built in Math Object
Javascript Built in Date Object
Javascript Built in Arrays Object
Javascript Built in Boolean Object
Javascript Built in RegExp Object
Javascript Built in JSON Object


 
SHARE THIS IF YOU LIKE!
submit to reddit
SUBSCRIBE FOR LATEST UPDATES
HAVE WE CONNECTED ON FACEBOOK?
TOP TUTORIALSTOP CODE EXAMPLESTOP LIVE DEMOLINKSSTAY CONNECTED
HTML Tutorial
HTML5 Tutorial
Bootstrap3 Tutorial
Javascript Tutorial
TypeScript Tutorial
AngularJS Tutorial
CSharp Tutorial
PHP Tutorial
Developer Tools
Javascript
AngularJS
Google MAP API V3
ASP.NET
Javascript
AngularJS
Google MAP API V3
Contact Us
Advertise with Us
Privacy Policy
Disclaimer
Stay connected. We actually like you. If you want to get up to the minute updates, then connect with us on your fav below.
 
Twitter   Linkedin   Facebook   Google+    RSS   Pinterest
 
Protected by Copyscape Original Content Checker
 
 
Copyright ©2017 www.techstrikers.com Unauthorized reproduction/replication of any part of this site is prohibited.