- Avoid polluting the global scope
Don't declare global variables if you don't need them to be global. Because they will be stored in the window object where there is a lot going on already. - Use strict equal
If you use==
a string and a number will be equal. Use strict equal===
to check the type. - Use
&&
and||
You can make your code shorter using these logic operators. - Convert values' types