Skip to content

Instantly share code, notes, and snippets.

@christinach
Last active December 6, 2022 15:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christinach/6f82f088ad3b5bdd9f4d1136249b4435 to your computer and use it in GitHub Desktop.
Save christinach/6f82f088ad3b5bdd9f4d1136249b4435 to your computer and use it in GitHub Desktop.
Variables:
Avoid global variables:
Variables can be accessed in local scope or global scope.
Local and global variable with the same name => javascript will prioritize the local variable.
Local variables are deleted once the local execution context is complete. Global variables
References
Use const or let for references
Avoid using var (https://developer.mozilla.org/en-US/docs/Glossary/Hoisting)
Functions:
Arrow function
Is a function expression not a function declaration
Cannot use a constructor. Is not called with new. Does not use 'this'.
Few characters shorter
Basic function
Name conventions:
Files
Functions
Class
Destructuring
Object
Array
Recursion
Avoid nesting more than two levels. It can be difficult to follow.
Comments
Use multi-line comment as: /** .... */
Use single line comment as: //
JS features that would like to use
Optional chaining operator
Semicolons
Use semicolons. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#automatic_semicolon_insertion
References:
https://eslint.org/docs/latest/rules/
https://arcticicestudio.github.io/styleguide-javascript/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment