Assignment to an undeclared variable automatically results in a global variable being created.
Avoid unnecessarily global variables.
2. Try to use Strict equality (===) instead of Abstract equality (==)
Sr. No | Abstract equality (==) | Strict equality (===) |
---|---|---|
1 | performs a type conversion | no type conversion |
3 | checks null | no null check |
2 | string literals are same from string objects | string literals are different from string objects |
3. You can assign commonly used window and document JavaScript objects to a variable to save bytes.
Using Global variable
4. You can create frequently used methods of document object such as getElementById and getElementByClass in a separate function
Using global variable with function :
No comments