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
3 Most Important JavaScript Tricks For Writing Fast, Memory-Efficient

3 Most Important JavaScript Tricks For Writing Fast, Memory-Efficient JavaScript They Don’t Teach You In School

By July 27, 2015 Blog No Comments
3 Most Important JavaScript Tricks For Writing Fast, Memory-Efficient

JavaScript is one of the most popular object-oriented programming languages used to create interactive effects within web browsers, but it can also be used in PDF documents, site-specific browsers, as well as desktop widgets. While learning JavaScript is far from being difficult, becoming a true JavaScript master requires years of experience. Today, we’d like to share with you a few of the most important JavaScript tricks and tips we learned through years of developing themes and plugins for WordPress. Let’s get to the good stuff!

Don’t Use The eval() Function

Using the eval() function is one of the most obvious signs of bad coding, because it can drastically slow down your code. Yet, you’d be surprised just how many developers keep using it, even though it’s incredibly easy to find an alternative way to get the job done. eval() essentially evaluates a string as if it were a variable. Fox example, imagine you have a variable called currentDate and want to alert the user. You could do it like this: alert(currentDate); However, if you use alert(“currentDate”), the alert wouldn’t display the value of currentDate; instead, it would display just the text currentDate.

3 Most Important JavaScript Tricks For Writing Fast, Memory-EfficientBuy Theme Open Demo

Eval solves that problem by evaluating the string as if it were a variable. The code would look something like this: alert(eval("currentDate"));

Since it has to invoke the JS interpreter, this function is considerably slower than most alternatives. If you take away just one of these important JavaScript tricks, make sure it’s this one, unless you’re gunning for slow and memory-heavy JavaScript.

Most Important JavaScript Tricks For Better Comments

Comment your code, and comment it well! That’s one of the most important JavaScript tricks you need to make sure you include in your development process. There are two types of comments in JavaScript: single-line and multi-line comments. Single lines are generally used for actual code comments and they are look like this: // This is a single-line comment
While multi-line comments can be used for commenting the code, they’re often used for removing or disabling parts of your code without deleting them. Multi-line comments will come really handy when you’re debugging the code, and they look like this: /* Multi-line comment
Another line
One more! */

3 Most Important JavaScript Tricks For Writing Fast, Memory-EfficientBuy Theme Open Demo

Place The Scripts At The Bottom Of The Document

One of the most important JavaScript tricks that affect the effectiveness and loading time of a website is the placement of the JavaScript elements. To make sure the page is optimized for speed, place the JavaScript at the bottom of your page, which will ensure the page elements load first before executing the script. This will come handy especially if you’re using JavaScript for action-related functionality like special effects after a button has been clicked.

Leave a Reply