background preloader

JavaScript Best Practices Part 1

JavaScript Best Practices Part 1
Javascript Best Practices, Part 1 Make it Understandable Choose easy to understand and short names for variables and functions. Bad variable names: Also bad variable names: incrementerForMainLoopWhichSpansFromTenToTwenty } createNewMemberIfAgeOverTwentyOneAndMoonIsFull Avoid describing a value with your variable or function name. Might not make sense in some countries: Works everywhere: Your code is a story - make your storyline easy to follow! Stick to a Strict Coding Style Browsers are very forgiving JavaScript parsers. Validate your code: Use Shortcut Notations Shortcut notations keep your code snappy and easier to read once you get used to it. This code var lunch = new Array(); lunch[0]='Dosa'; lunch[1]='Roti'; lunch[2]='Rice'; lunch[3]='what the heck is this?' Is the same as... var lunch = [ 'Dosa', 'Roti', 'Rice', 'what the heck is this?' if(v){ var x = v; } else { var x =10; } var direction; if(x > 100){ direction = 1; } else { direction = -1; } var direction = (x > 100) ? Related:  Coding tutorialsJavaScript

JavaScript Best Practices Part 2 | Thinkful Programming Guides Optimize Loops Loops can get terribly slow in JavaScript. Most of the time it’s because you’re doing things in them that don’t make sense. Don’t make JavaScript read the length of an array at every iteration of a for loop. Store the length value in a different variable. var names = ['George', 'Ringo', 'Paul', 'John']; for(var i=0;i<names.length;i++){ doSomethingWith(names[i]); } var names = ['George', 'Ringo', 'Paul', 'John']; for(var i=0,j=names.length;i<j;i++){ doSomethingWith(names[i]); } Keep computation-heavy code outside of loops. You can create the DOM nodes in the loop but avoid inserting them to the document. Keep DOM Access to a Minimum If you can avoid it, don’t access the DOM. Reason: It’s slow and there are all kinds of browser issues with constant access to and changes in the DOM. Solution: Write or use a helper method that batch-converts a dataset to HTML. Seed the dataset with as much as you can and then call the method to render all out in one go. Don’t Yield to Browser Whims

JavaScript Tutorial Training videos, books & free excerpts - Crane Softwrights Ltd. The materials found in the products listed below are the basis of hands-on training delivered publicly and privately by licensees around the world. Special note regarding the hyperlinked PDF files: The 1-up versions of the books are bookmarked, extensively indexed and hyperlinked. Every page has hyperlinks into the index at the bottom center. Every page number in the index is hyperlinked into the body of the text. Links to external specifications bring up a browser window navigated to the section cited. 1. Overviews of training videos (for a local DVD-ROM simulation, our test video presents as an actual (short) running sample of the technology): 1.1. Crane has introduced a "try and buy" policy where the complete content of the book can be downloaded in a 2-pages-per-page compact format (hence the page links built into the book are non-functional). In contrast, the free preview excerpts are exactly that: free and only an excerpt of the content. 2. 2.1. 3. 3.1. 3.2. 3.3. 3.3.1. 4. 4.1. 5.

JS: The Right Way miniBloq JavaScript: The Good Parts: Douglas Crockford: 9780596517748: Amazon.com: Books DZone We’re not sure whether it’s a good thing or a bad thing, but today’s mobile users are a hard crowd to please. When they begin interacting with an interface, they very quickly lose patience with anything even slightly below standard, and can have little interest in learning to use confusing or unpredictable UIs. If you’ve ever found yourself so enraged with an app you’re ready to throw your phone against the wall, you’ll understand the need for creating interfaces which are user friendly. We see enterprise apps make the same mistakes time and again - navigation is confusing, inputs and outputs are unclear and users end up feeling alienated from the product. inappropriate display choicesvariety for the sake of varietytoo much informationnoisy patterns and colorsinconsistency in coding and ordering Fortunately, there are a number of simple rules you can follow to ensure you avoid these classic mistakes. 1. Crucial considerations include: Can users access data rapidly? 2. 3. 4. 5.

JavaScript - Tuts+ Code Category Have you ever got excited by your idea for a website, but found yourself becoming miserable when trying to make it dynamic and actually run it on a server? With Parse.js, everyone who understands the basics of HTML, CSS, and JavaScript can create dynamic websites and working web apps. This tutorial is going to take you through the process of creating a blog system step by step with Parse.js. And by the end of this series, you should be able to create your own CMS site with ease. Have you ever got excited by your idea for a website, but found yourself becoming miserable when trying to make it dynamic and actually run it on a server?

Infographic: The Entire JavaScript Language in One Single Image Chinese-based developer Yusheng, has created a nice graphic that assembles the entire JavaScript programming syntax into one single all-encompassing image. Regardless of what the TIOBE Index says, JavaScript, and not Java, is the hottest programming language right now. This popularity was won very hard, having to fight through a period where the language seemed to have stood still with no new features being released for a period of four years. Despite this, developers rushed to the language, mainly due to the technologies being developed on top of it, and more specifically Node.js. If today some of you want to delve into JavaScript in the upcoming future, there are many tutorials you can find online, all great resources for learning the language's fundamentals from the ground up in a matter of days. But if things are constantly escaping your memory, Chinese-based developer Yusheng has assembled a nice mind map of the entire JavaScript language syntax, complete with code examples.

JavaScript is Sexy | Learn modern web application development with JavaScript Pyjs ericelliott/essential-javascript-links

Related: