JavaScript 最佳实践:提升你代码质量的一些建议和技巧

阅读 3207
收藏 202

Learning new things everyday is part of what makes being a rational human being great. And as developers, it is part of our job to learn new things continuously, whether or not these things are from positive learning experiences.

In this tutorial, I will point out a few important JavaScript best practices so you don’t have to learn it the hard way. Get ready to level to your code!

1. Avoid polluting the global scope

Declaring variables is a lot of fun. Sometimes, you may declare global variables even if you don’t want to. In today’s browsers, the global variables are stored in the window object. So, since there’s a lot of stuff going on there, you may override default values.

Let’s suppose you have an HTML file which contains a