Friday, 20 February 2015

5 Tips To Become Better JavaScript Developer!

JavaScript is still a mystery to a lot of people. With it’s growing popularity with things like Node.js, Angular.js, and jQuery, people are wanting to know more and more about the language

With more beginners jumping in, there’s room to make mistakes that JavaScript will more than willing let you do. Right now, JavaScript is being bombarded with new frameworks and libraries that completely change our regular workflow. In this article we have listed 5 simple and quick JavaScript tips that will help beginners improve their code quality.

1.Work on API for security

Beginners often think that hiding elements from user using JavaScript is security but you should rather focus on your lack of obedience, that will make you a better coder. It’s always best to work with API layer so it will help you put up real security walls. API checks everything that passes through it. So API can prevent access to the unauthenticated call.

API should strictly not produce any information that user doesn't have the permission to access. It is best to build your own API with multiple layers of protection. JavaScript doesn't automatically hide and mask things.

2.Use Strict mode while writing the code

Strict mode was introduced in ECMA 5. It allows you to put a function or an entire script into strict operating context. It eliminates some of the silent JavaScript errors by throwing the errors explicitly. It is capable to throw exceptions when relatively unsafe actions take place. And sometimes strict mode code can run faster than non strict mode code. As currently all the major browsers support this feature you should start using strict mode.

3.Write easy to understand code

You must not write a confusing code, it will just make things worse. You should avoid the shortcuts while writing the code. A function like ShoeBox(); can be represented as ShBx(); but, that is not easy to understand. It is necessary to write the code as if you are writing the story in normal language. This approach really helps while debugging and beta testing.

Beginners often focus on number of lines and speed of coding. But to be fair, in the end, whether the app works flawlessly or it is buggy is all that matters. Number of lines of codes and efficiency of the app, both things are totally irrelevant.

4. Cache the length while looping

Beginners often forget this while writing a code and then end up debugging the thousands of lines of codes. While looping through a JavaScript array you can cache the length so that the overall performance is better. Be careful while creating an inner loop. You need to name the length variable differently in the inner one.

5.Test

To improve your confidence that code will behave as expected, write unit tests using a framework such as Jasmine or QUnit for each of your functions, using both expected and unexpected input parameters.

Run these tests in multiple browsers across multiple operating systems. if your code is stored in GitHub, you can take advantage of BrowserSwarm, a tool that automatically runs your unit tests when you commit your code

No comments:

Post a Comment