# Javascript Style Guide Naming convention: - Lower Camel Case: Variables - Upper Camel Case: Classes and methods **Do Not** - Avoid CSS property definition manipulation within a javascript file; instead define all CSS properties in the stylesheet. - Instead use javascript to refer to selectors on a class or ID level. Function Declarations - Note: - Cannot recast variables (no loose types) - Concatenating strings with non-string variables is fine as long they are being assigned to a string variable - Functions should follow verb-noun format - Variable declarations clumped together - One empty line before ending a code block ``` class MyClass { let someVar; let someVar2; // DoFunction() description here // param1: description // param2: description // return: description DoFunction : function( param1, param2 ) { let myVar; let myVar1; let myVar2; // logic } } ``` <br/> If Statements - ``` if( condition ) { // code } else if( condition ) { // other code } ``` Inline-If Statements - ``` var ? ifTrue : else; ``` Do-While Statements - ``` do { } while( condition ); ``` Enhanced For Loops - Note: - The preferred option to iterate through a collection or object ``` for ( let item of list ) { // iterate with item } for ( let property in object ) { // iterate over object properties } ``` For Loops - Note: - Use when you specifically need to index in a for loop ``` for ( let index = 0; index < list.length; index++ ) { // iterate through index } ``` Nested Loops - Note: - Nested loops should be the same loop type # Header Classes should have a header with the name of person who created the class and a description of what the class does ``` ///////////////////////////////////////////////////// // // Name: Some Class // Author: Some Author // Description: some Description // /////////////////////////////////////////////////// ```