Friday, 12 January 2018

Javascript Tips and Tricks

Javascript Tips and Tricks

Introduction

In this article, we learn about import consideration while we are working with javascript.This information will help you to prevent most common mistake while development. JS tips and Tricks at one place.

Description

Quick tips
  1. Use === while comparing two variable instead of ==
  2. Remember undefined is not null
  3. Remember javascript falsy value:   0, '', NaN, null, undefined
  4. Remember javascript truthy value:   '0', 'any string', [] (Empty array), {} (Empty object), 0 (any non-zero number)
  5.  Always declare all variables at the beginning of every scope
  6.  "use strict"; In javascript to avoid unwanted bug due to a variable.
  7. Avoid global variable declaration
  8. Reduce globals e.g var name='abc', isValid=false; Should be writen as var common={name:'abc', isValid:false};
  9. Always declare local variables
  10. Never declare Number, String or Boolean Objects ( e.g. Never use: new Number(1), new String("abc"), new Boolean() )
  11. Use {} instead of new Object()
  12. Use "" instead of new String()
  13. Use 0 instead of new Number()
  14. Use false instead of new Boolean()
  15. Use [] instead of new Array()
  16. Use /()/ instead of new RegExp()
  17. Use function (){} instead of new Function()
  18. Avoid Using eval()
  19. Don't use short hand  e.g Always use curly bracket with conditional operation
  20. Place scripts at the Bottom of page
  21. Declare Variables Outside of the from loops and conditionals (such as if, for, while, switch and try)
  22. Properly comment your code
  23. Never pass a string to SetInterval and SetTimeOut. Instead, pass a function name.
  24. Always, Always Use Semicolons
In this article we have get idea of lots of JavaScript tips and tricks and best practice consideration while development.

1 comment:

  1. Yeah, somebody may say that these things should be sort of well-known not only for frontenders, but for lads who deal with coding as well. Nevertheless, you can never be thorough, I would say, so thanks for that summary! To be frank, I've just started my way through programming fundamentals with javascript itself, because I think it's the best option to get the whole programming logic easily. Now 2 months have passed and my skills are strong enough in order to write and run some tricky scripts like this javascript snake game https://explainjava.com/snake-game/ Obviously, I did some peeks while writing it, but I tell you for sure, afterwards I've felt like this call-it exercise had given me such a confidence

    ReplyDelete

Friday, 12 January 2018

Javascript Tips and Tricks

Javascript Tips and Tricks

Introduction

In this article, we learn about import consideration while we are working with javascript.This information will help you to prevent most common mistake while development. JS tips and Tricks at one place.

Description

Quick tips
  1. Use === while comparing two variable instead of ==
  2. Remember undefined is not null
  3. Remember javascript falsy value:   0, '', NaN, null, undefined
  4. Remember javascript truthy value:   '0', 'any string', [] (Empty array), {} (Empty object), 0 (any non-zero number)
  5.  Always declare all variables at the beginning of every scope
  6.  "use strict"; In javascript to avoid unwanted bug due to a variable.
  7. Avoid global variable declaration
  8. Reduce globals e.g var name='abc', isValid=false; Should be writen as var common={name:'abc', isValid:false};
  9. Always declare local variables
  10. Never declare Number, String or Boolean Objects ( e.g. Never use: new Number(1), new String("abc"), new Boolean() )
  11. Use {} instead of new Object()
  12. Use "" instead of new String()
  13. Use 0 instead of new Number()
  14. Use false instead of new Boolean()
  15. Use [] instead of new Array()
  16. Use /()/ instead of new RegExp()
  17. Use function (){} instead of new Function()
  18. Avoid Using eval()
  19. Don't use short hand  e.g Always use curly bracket with conditional operation
  20. Place scripts at the Bottom of page
  21. Declare Variables Outside of the from loops and conditionals (such as if, for, while, switch and try)
  22. Properly comment your code
  23. Never pass a string to SetInterval and SetTimeOut. Instead, pass a function name.
  24. Always, Always Use Semicolons
In this article we have get idea of lots of JavaScript tips and tricks and best practice consideration while development.

1 comment:

  1. Yeah, somebody may say that these things should be sort of well-known not only for frontenders, but for lads who deal with coding as well. Nevertheless, you can never be thorough, I would say, so thanks for that summary! To be frank, I've just started my way through programming fundamentals with javascript itself, because I think it's the best option to get the whole programming logic easily. Now 2 months have passed and my skills are strong enough in order to write and run some tricky scripts like this javascript snake game https://explainjava.com/snake-game/ Obviously, I did some peeks while writing it, but I tell you for sure, afterwards I've felt like this call-it exercise had given me such a confidence

    ReplyDelete