background preloader

Javascript

Facebook Twitter

Tips and tricks about JavaScript from Google. JavaScript is now a very popular client side language.

Tips and tricks about JavaScript from Google

It's flexible, powerful but easy to make mistakes. So good programming style is better for you to write efficient and readable JavaScript codes. Here are some tips and tricks about JavaScript from Google. True and False Boolean Expressions The following are all false in boolean expressions: nullundefined'' the empty string0 the number But be careful, because these are all true: '0' the string[] the empty array{} the empty object This means that instead of this: you can write this shorter code (as long as you don't expect x to be 0, or the empty string, or false): 25 Useful JavaScript Libraries And Tools. A huge number of web designing and development tool is available on the web, making it really tough to find the good ones that actually work.

25 Useful JavaScript Libraries And Tools

Many not-so-popular tools are also present which are really nice but don’t get the deserved attention because they are lost in the crowd! This is where lists of specific type of tool and collections come in handy, as they provide you information in a brief and compact way regarding the best popular and the not-so-popular tools at one place. We have history of always bringing you some really cool collections and roundups of some of the best web designing and development resources available out there which can help you enhance your productivity and achieve your targets easily and quickly. We have compiled a list of 25 Useful JavaScript Libraries And Tools. The Expert Javascript Programmer. December 6, 2009By Geoffrey Grosenbach I spent the weekend reading Douglas Crockford’s essays on Javascript.

The Expert Javascript Programmer

He was an independent advocate for Javascript back when most programmers hated it. He was responsible for making JSON a standard for data interchange, even between completely different languages. There are some classic essays in there and it only took a few hours to read all the articles on the front page. You can forgo the 90’s web design style by using the Readability bookmarklet either on the desktop or mobile1. I use style: novel, size: large, margin: narrow.

If you don’t use Javascript, you’ll learn some valuable lessons from a skilled programmer and tech visionary. His opinionated decisiveness and surly delivery produce some real chestnuts. It helps to periodically remind oneself of these clear truths. At least one other clear truth emerged while reading. If.js // Possible errorif (a === b) c = d; e = f; // Recommendedif (a === b) { c = d;}e = f; JavaScript Garden. Although JavaScript deals fine with the syntax of two matching curly braces for blocks, it does not support block scope; hence, all that is left in the language is function scope. function test() { // a scope for(var i = 0; i < 10; i++) { // not a scope // count } console.log(i); // 10} There are also no distinct namespaces in JavaScript, which means that everything gets defined in one globally shared namespace.

JavaScript Garden

Each time a variable is referenced, JavaScript will traverse upwards through all the scopes until it finds it. In the case that it reaches the global scope and still has not found the requested name, it will raise a ReferenceError. The Bane of Global Variables // script Afoo = '42'; // script Bvar foo = '42' The above two scripts do not have the same effect. Again, that is not at all the same effect: not using var can have major implications. Learning JavaScript Design Patterns. I would like to thank Rebecca Murphey for inspiring me to open-source this mini-book and release it for free download and distribution - making knowledge both open and easily available is something we should all strive for where possible. I would also like to extend my thanks to the very talented Alex Sexton who was kind enough to be the technical reviewer for this publication.

I hope that it helps you learn more about design patterns and the usefulness of their application to JavaScript. Volume 2 of Essential JavaScript Design Patterns is currently being written and will be more detailed than this first edition. The ETA for it's online release is late Q4, 2011. For more detailed coverage of specific patterns, you may be interested in my posts on the Pub/Sub (Observer) or Decorator patterns. At the beginning of this book I will be focusing on a discussion about the importance and history of design patterns in any programming language.

Patterns are not an exact solution. JavaScript Constructors. Because syntax and control structures look very similar in classic OOP languages (Java, C#) to JavaScript, it can be easy for experienced developers to jump-in, make progress, and then shoot themselves in the foot due to misunderstanding core differences in underlying language design.

JavaScript Constructors

One of those core differences is how functions can function as objects with constructors. In a classic OOP language, a class, constructor, and usage might look something like this: Although the syntax is similar, doing something like this in JavaScript will land you in a bad place: Scope The first and most pressing issue is scope management. Primarily, the problem is with the scope of the this keyword with in functions. However, in side of a JavaScript function, the this keyword refers to the global scope, or the window object. For the uninitiated, this can cause big problems. But wait, there is a solution! However, if you have ever written a line of jQuery, you might be shaking your head in disagreement.