PHP Versus JavaScript Comments

Comparing PHP vs. JavaScript comments. Software developers often have to use two languages such as PHP and JavaScript for website and web application development.  It is sometimes hard to remember which language constructs belong to which language. This article compares PHP versus JavaScript comments, showing which language supports which types of comments.

PHP Versus JavaScript Comments Comparison

When commenting code in PHP and JavaScript, the following comment types are available.

PHP Versus JavaScript Comments
PHP Versus JavaScript Comments

More details on PHP and JavaScript comments follow in the next two sections.

PHP Comments

PHP supports three types of comments. Two comments are single line and one is multi-line. The code below shows the three types of comments available in PHP, followed by a single line of PHP code.

A PHP single line comment can start with a double forward slash // or with a hash character #. A PHP multi-line comment starts with a forward-slash and asterisk /* and ends with a asterisk and forward slash */.

JavaScript Comments

JavaScript supports two types of comments. One single line and one multi-line as shown below.

The above code shows the two JavaScript comment types followed by a single line of JavaScript code. Single line comments in JavaScript start with a double forward-slash //. Multi-line comments in JavaScript start with a forward-slash and asterisk /* and end with an asterisk and forward-slash */.

HTML and CSS Comments

Because they are related to the technology that PHP and JavaScript are widely used on, HTML and CSS comments are shown below.

HTML has only one type of comment format. CSS also has only one type of comment format which is the same as PHP and JavaScript multi-line comments.

Using Comments in Code

As with all programming languages, comments are notes about the code that are human readable. Comments are always ignored by the compiler or interpreter.

In PHP scripts, comments are never sent to the web browser. They always remain in the script on the server.

JavaScript comments can be removed from scripts by using a minifying program. This is done to reduce the size of the script and therefore the load time of the script and web page. A local copy of the script can be kept for development. The script can then be run through the minifying program to generate a smaller script for production that will be loaded to the server.

Leave a Reply

Your email address will not be published. Required fields are marked *