Javascript Best Practices 1685180754
Javascript Best Practices 1685180754
EMMANUEL
JAVASCRIPT
BEST
PRACTICES.
@Ezenagu Emmanuel
01
Avoid Global
Variables
• Minimize the use of global variables.
Declarations on Top
All declarations should be placed at the beginning of
each script or function as good coding practise.
• A cleaner code
• Give users a single location to look for local variables.
• Make it simpler to avoid undesirable (implied) global
variables.
• Reduce the likelihood of unwanted re-declarations.
05
Example;
06
Initialize Variables
When you declare variables, you should always
initialise them.
This will:
Beware of Automatic
Type Conversions
• JavaScript is a loosely typed language.
Use Parameter
Defaults
• When a function is called with an unspecified
argument, the value of the unspecified argument is
set to undefined.
Example;
17
Example;
19
Example;
21
@Ezenagu Emmanuel