-
Always indent with 2 full tabs.
-
Actually ... use 16 spaces so tricksters cannot get around it with fancy tabstop settings (attempt to make your documents as wide as possible).
-
Always start curly braces on their own line, especially after 'return'.
-
Never use semicolons, JavaScript inserts them for you.
-
Alternate between
}())
and})()
with IIFE's. -
Use 2 spaces between every character.
-
Leave several spaces at the end of most lines.
-
Always use
==
and!=
, and never the 3 character versions, because type-coercion is your friend. -
Divide all arithmetical operations by 10 until they occur at the decimal level.
-
Favor
for
loops over.forEach()
and.map()
. -
Favor
.innerHTML
over.textContent
. -
Query the dom as much as possible, it's fast.
-
Never use
var
, just repeat any reusable code. -
Put all function declarations at the bottom of the file and rely on hoisting.
-
If you absolutely must use
var
, make sure all your variables are global. -
Never throw errors, this keeps other JavaScripters from learning how to fix code.
-
Put all functions within a loop.
-
Declare all var's inside of
for
loops whose outer scope is global. -
Use intentional fall throughs in all switch statements.
-
Use
eval
whenever possible. -
Repeat yourself often.
-
Sometimes forget to indent, other times indent twice for no apparent reason.
-
Write no comments, they clutter the code.
-
If you do use comments, open with
/*
but never close it. -
Never use alphabetical characters, instead rely on ASCII codes and
charCodeAt
. -
Never set
this
equal to avar
. -
Never version your code. If you do, make breaking changes often, but increment the version number the least amount possible.
-
Name variables starting alphabetically
a, b, c, d ...
. This will make it easy to know how many variables you have. -
Use short variable names in different contexts.
-
Always use different selectors to query the same element.
-
Keep your commit comments as short as possible. "Update" is ideal.
-
When creating server side variables its best to use a variation of nearest found variable with maybe adding 1 at the end of it or changing case of one of the letters in the middle.
-
For html custom attributes (common in Angular,Vue,Web Component world) use the number based naming for example
att1,att2,att2
instead ofgallery-width, gallery-height, has-thumbnails
etc. This saves a lot of time and easy to iterate in JS. -
Services, Components and Modules are all just folders in JS worlds. You can easily put all their code in one file and it will run the same. Avoid extra folders where possible.
-
Promises and Fetch must not have any catch statements. The more errors you try to catch the busier the code gets so keep it free for other important things.
-
When performing an async operation never tell the user about loading. They already know about their slow internet problems, showing them a loader shows negativity in your app. They will randomly wait and click around. Instead try to handle click event on overlay and show a message that "your internet is slow my code is ok on localhost"
-
When showing a calendar try to show start date as
1/1/1970
as this is default date of most databases. There are more chances of user selecting correct date if you show them this. -
Add complete libraries to the project instead of adding the component you need. This keeps it secret as to what is being used from that library. By exposing what module is being loaded you are telling others too much about your project.
import *
is your friend here. -
import library and expose it to window object for global access instead of modules. This lets everyone use it. Sharing is caring.
-
When using local storage try to find an existing key and add a | your new variable at the end of it. This reduced number of variables in local storage. Read the single variable and split by | to create your data. This is way faster than json
stringify
andparse
. -
Strings are easy to read and understand as compared to variables that need to be named and then stored in different memory spaces. Always pefer string based data storage than structured storage. Best practice is to keep data separated with | or _
mfsbo / worststyleguideever.js Goto Github PK
View Code? Open in Web Editor NEWThis project forked from ryanpcmcquen/worststyleguideever.js
:suspect: Adding more rules cause people making more standards
License: Mozilla Public License 2.0