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 downshift + right/left
- Highlight code right and leftcmd + right/left arrow
- move cursor to beginning/end of linecmd + up/down arrow
- move cursor to beginning/end of fileoption + up/down arrow
- move line up/downshift + option + up/down arrow
- copy line up/downcmd + /
- Comment out a line of codecmd + shift + /
- Comment out multiple lines of codecmd + d
- Select the next instance of the selected wordcmd + shift + l
- Select all instances of the selected wordcmd + shift + f
- Search for a string in the projectcmd + 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.