Warning: include(nectar/meta/meta-config.php) [function.include]: failed to open stream: No such file or directory in /home/content/18/9019618/html/v2014/wp-content/themes/salient/functions.php on line 4650

Warning: include() [function.include]: Failed opening 'nectar/meta/meta-config.php' for inclusion (include_path='.:/usr/local/php5/lib/php') in /home/content/18/9019618/html/v2014/wp-content/themes/salient/functions.php on line 4650
Are You Making These Common JavaScript Mistakes?

Are You Making These Common JavaScript Mistakes?

By June 6, 2015 Blog No Comments
Are You Making These Common JavaScript Mistakes?

JavaScript is one of the easier programming languages to learn, but that doesn’t mean you don’t have to pay close attention when writing the code. There are countless tips and tricks online, as well as standards and best practices when it comes to JavaScript that can affect the usability and performance of your code. Yet, so many developers keep repeating the same mistakes that can easily be avoided with some planning and foresight. Read on to find out what some of the most common JavaScript mistakes are, and how avoid them.

The Devil Is In The Detail

If you omit a comma or overlook a typo when writing an email or a blog post, your readers will still get the message you’re trying to convey. However, when writing JavaScript code, a missing semicolon, for example, can bring down an entire web page, making you spend countless hours hunting down the error as a result.

Are You Making These Common JavaScript Mistakes?Buy Theme Open Demo

Every JavaScript statement must end with a semicolon. However, when JavaScript is parsed, there is a process known as automatic semicolon insertion, so why should you care? Every time you rely on automatic semicolon insertion, you’re risking bugs which are difficult to locate because white space changes semantics. This is one of those common JavaScript mistakes you can avoid by making a habit out of ending JavaScript statements with semicolon yourself, instead of relying on automatic processes.

Unnecessary DOM Interactions Are One Of The Most Common JavaScript Mistakes

Even though the Document Object Model, or the DOM, isn’t technically JavaScript, working with JavaScript does involve dealing with it most of the time. The DOM allows programs and scripts to dynamically access and update the content, structure and style of documents, but each JavaScript and the DOM interaction is an expensive operation, which can be easily avoided. Instead of looking up the same DOM node multiple times, you can store it in a variable or array the first time you look it up and reference it later on.

Are You Making These Common JavaScript Mistakes?Buy Theme Open Demo

Be Consistent When Using Quotes

Not using quotes consistently throughout the code is one of the most common JavaScript mistakes most beginners make. JavaScript is rather flexible when it comes to using quotes, allowing you to use both single and double quotes, depending on your own personal preferences. However, if you open a string with one type of quotes, make sure you close it with the same type, especially when you’re embedding one string into another. For example, use double quotes for the embedded statement, and single quotes for the statement that contains the embedded one.

Leave a Reply