I know a few of my rookie javascript friends/family could use a friendly reminder about syntax. Syntax is important for each language you learn so make sure you review the basics.
Javascript Syntax Basics:
- Each line that should be run needs a semicolon at the end
- Functions don’t need semicolons after the closing curly bracket
- Every time you open a curly bracket, indent your code one tab (or 2 spaces) for readability
- When you are writing a callback, finish writing out the method, parens, and semicolon before writing your callback with the parens. This will prevent you from forgetting to close your parens or missing the semicolon at the end. For instance:
someString.map(); // write out the variable and method through the semicolon someString.map(function(value){return value;}); // then you can write your callback
- When writing if, if/else, loops, switches, etc, try to write out the conditions before adding code within the cases For instance:
// start by writing your if conditions if (someNumber > 10) {} // then add your code within the curly brackets if (someNumber > 10) { return true;}
HTML Syntax Basics:
- You need a <html> at the top of the doc
- Your file needs a <head></head><body></body> with the html
- <head> should only have your metadata, css links
- <body> will have the content of the page you are displaying
- place your javascript scripts and links at the end of the body
- Whenever you open a tag that will be more than one line long, indent with a tab
- Line up closing tags with their opening tags
CSS Syntax Basics
- you can apply the same styles to a selection of tags/classes/objects by listing them with comma separation before the style
- child inherit from their parents
- don’t use !important unless you have to
This is just a start. As more tips come to mind, I will add to this list. If you have any notes to add, please send me a comment.