JavaScript Quick Tips

Here are a few JavaScript tricks and tips I have learned.

These lessons were learned working in an ASP.NET, AngularJS, and C# environment using Visual Studio 2013.

  • For AngularJS views, place curly braces in the HTML to see an object and all of its properties, i.e. {{person}} will show all of the properties and values for the person object.
  • Use Internet Explorer with Visual Studio to set break points in the JavaScript file while debugging. Thanks go to Tammy for giving me this tip.
  • Use alert messages and console.log to see the variable’s current value or type. Sometimes I use alert just to make sure the program is reaching the section of code.
  • Send the entire object and use the properties as needed. I was wasting time sending just individual elements when I could have just sent an entire object. For instance, instead of sending:
    name:”john”, age:25
    I learned to just use:
    var person = {name: “john”, age: 25}
    and to send the entire person object.
    Then on the server side I can use setters and getters for a Person object which will have properties Name and Age.
  • Watch out for null and undefined variables. I am not entirely sure how to avoid these problems but I am thinking the solution is to initialize my variables and also set my variables when I reset them.

These tips are pretty basic but hopefully I will be able add even more tips as I fail a lot and make mistakes 🙂 learn and improve even more…

 

 

 

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s