JavaScript Comments
Edited
Use comments to add descriptions to your code. Lines with comments will not be executed. Comments are helpful for you or your teammates to understand your code better.
Single Line Comments
Use two forward slash characters //
to make a new comment. Anything after that will not be executed.
// This code will get you to the treause.
forward(); // Go forward.
turnRight(); // Turn right.
forward(); // Go forward again to reach the treasure.
Commenting Out Code
Sometimes, if a code is not running, programmers will comment out code to see what's working and what's not. This way, they don't have to delete code.
// The next command is commented out.
// forward();
Multiline Comments
Multiline comments are made starting with /*
and ending with */
. Any code in between these markers will be ignored.
Multiline comments are used to give more detailed documentation about your program.
/*
Here are the commands to get to the treasure. First, we'll
start moving forward one square. Then we turn right so that
we point down. Then we move forward again so we get further
ahead. We'll be on the treasure after the last step!
*/
forward();
turnRight();
forward();