Comments & Shortcuts

September 26, 2024

Comments & Shortcuts

All programming languages have commenting functionality. Comments are used for documenting your code and explaining things in a human readable way. Often times, multiple developers work on the same code base and comments are used to explain what a certain piece of code does.

Comments are also used to disable code. This is useful when you want to test something out without deleting the code.

You may also use comments as a todo list. This is useful when you want to keep track of what you need to do next.

Single Line Comments

In JavaScript, single line comments are created by using two forward slashes //. Anything after the two forward slashes will be ignored by the JavaScript interpreter. This is useful when you want to add a comment to a single line of code.

// This is a single line comment

console.log('Hello World'); // This is a single line comment

Multi Line Comments

In JavaScript, multi line comments are created by using /* and */. Anything between the two symbols will be ignored by the JavaScript interpreter. This is useful when you want to add a comment to multiple lines of code.

/*
This is a multi line comment
*/

Useful Shortcuts

I just want to go over some helpful keyboard shortcuts. These work for VS Code, but many of them are universal and will work in most text editors.

  • shift + up/down - Highlight lines of code up and down
  • shift + right/left - Highlight code right and left
  • cmd + right/left arrow - move cursor to beginning/end of line
  • cmd + up/down arrow - move cursor to beginning/end of file
  • option + up/down arrow - move line up/down
  • shift + option + up/down arrow - copy line up/down
  • cmd + / - Comment out a line of code
  • cmd + shift + / - Comment out multiple lines of code
  • cmd + d - Select the next instance of the selected word
  • cmd + shift + l - Select all instances of the selected word
  • cmd + shift + f - Search for a string in the project
  • cmd + shift + o - Search for a file in the project

You aren't going to remember all of these right now. Try and use a few of them while you're coding and it will become second nature. I use these shortcuts all the time and they make my life a lot easier.