JavaScript
HTML
CSS
jQuery
PHP
SQL
WordPress
JavaScript Tutorials

Overview

JavaScript comments are used to create notes about what the code block does and how it works, and can also be used to temporarily prevent code execution. Comments are not displayed in the browser, and are great for future reference.

Single Line Comments

Any text between the // and the end of the line will be ignored by the browser (will not be executed). Anything on the line before the // will run normally. And anything on lines after the comment will run normally.

				
					// this is a comment

let x = 5; // this is also a comment
let y = 8;
				
			

Multi-line Comments

JavaScript comment can also wrap to multiple lines and anything between the /* and */ will be the comment, including any code that you don’t want the browser to run. This is called “commenting out” code.

				
					/* this is a 
a much longer
comment 

let x = 5;
*/
				
			

As mentioned above, JavaScript comments can also be used to “comment out” a section of code that you’d like to keep intact for future use, but “turn off” for the time being. By wrapping a comment around the code, it will not be implemented by the browser.

The structure of the comment stays the same, but the comment itself is the code you no longer want the browser to run. In the following, we comment out the height of 40px and instead use window.innerHeight.

				
					// variables
let width = window.innerWidth;
let height = /* 40px */ window.innerHeight;
let x = document.getElementById('demo');

// write the URL to the HTML element
x.innerHTML = 'Width: ' + width + '<br>Height: ' + height;
				
			

We’d like to acknowledge that we learned a great deal of our coding from W3Schools and TutorialsPoint, borrowing heavily from their teaching process and excellent code examples. We highly recommend both sites to deepen your experience, and further your coding journey. We’re just hitting the basics here at 1SMARTchicken.

JavaScript
HTML
CSS
jQuery
PHP
SQL
WordPress

Why 1SMARTchicken?

This site was built and is maintained to benefit my autistic son.
See More →

My Son's Name is Johnny

He was diagnosed as autistic quite late, at age four...
His story

Buy Me a Coffee

Thanks for your support!

Feedback

If you see an error on the page or the code itself is incorrect or incomplete, or just plain wrong, please let us know. We’re always learning. NOTE: we do not sell your information and will not send you spam emails.