Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

TUTORIAL: Comment Switches

Featured Replies

Comment switches are comments that hide parts of your code while keeping other parts active. They allow simple debugging and allow you to "go back to the drawing board" without having to re-write everything you've had to remove.

 

I first saw these on another forum and I've named them after the users that first introduced me to them. I don't know if they have another, official, name and I would be fascinated to learn whether they do.

 

The Jaap Comment Switch

The Jaap Comment Switch toggles two pieces of code. There is no limit to the amount of code this can hide.

 

Availability

This comment switch works in:

  • JavaScript
  • PHP
  • ActionScript
  • any other language that has both single-line and multi-line comments

 

Usage

The switch is very straight forward:

/*
previous_function();
/*/
new_function();
//*/

previous_function() is completely hidden and will not fire. new_function() is active.

 

Switching

To switch this code, all you need to do is add a slash to the first line.

//*
previous_function();
/*/
new_function();
//*/

Now, previous_function() will fire while new_function() is hidden.

 

 

The Phlip Comment Switch

The Phlip Comment Switch allows many pieces of code to be hidden and activated.

 

Availability

This comment switch works in:

  • CSS
  • JavaScript
  • PHP
  • ActionScript
  • any other language that has multi-line comments

 

Usage

This comment switch requires the last line to be left alone.

/** /
function_one();
/** /
function_two();
/** /
function_three();
/**/

In this example, all three functions are hidden.

 

Switching

To switch this code, remove or replace the space in the comment before the piece of code you'd like to activate or hide.

/**/
function_one();
/** /
function_two();
/** /
function_three();
/**/

function_one() will now fire while the other two are hidden.

Multiple code pieces can be active at the same time. For example, the following piece of code will fire function_one() and function_three() while keeping function_two() hidden.

/**/
function_one();
/** /
function_two();
/**/
function_three();
/**/

 

 

Conclusion

I always find these switches useful when I'm working on a busy site, allowing me to write new code and test it while being able to replace it with the original (working) code in seconds.

 

I hope everyone here finds a use for these comment switches. Please feel free to reply with any other switches you've come across

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.