JavaScript Tips

Share:
1. Don't forget to use keyword var when assigning a value for the first time.
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 :

Hi! I am Sartaj Husain. I am a Professional Software Developer, live in Delhi. I write blogs in my free time. I love to learn and share the knowledge with others because it is no good to try to stop knowledge from going forward. So free posts and tutorials. more..

No comments