Home > javascript > JavaScript 101

JavaScript 101

This week in the company’s  mentoring session, I have talked about AJAX and JavaScript. Most of developers have awful experiences when working with JavaScript and think JavaScript is just a bunch of crap. However I think JavaScript is not a bunch of crap, it has good parts too.

The reason people finds JavaScript hard to work with are:
1. JavaScript is different language; you need to program in a different way
2. Limited IDE support for JavaScript
3. Lots of bad books on JavaScript
4. People do not put effort on learning how to program JavaScript

How we learn JavaScript?

To start with, go to read Douglas crockford’ javascript website and watch all the Video Tutorials below. It will convince you that JavaScript is good Language that worth your time and effort to learn.

Then you need some good books on JavaScript. My recommendation are : JavaScript: The Good Parts and JavaScript: The Definitive Guide

Finally,when you are programming in JavaScript you need always use jslint to QA your JavaScript Code. jslint is a code analysis to tool which help you to correct any mistakes and bad coding practices used in JavaScript.

Best practices when coding JavaScript

1. Avoid using Equal(==) and not equal(!=)

These operators can do type coercion(e.g. “”==false will evaluate to true )

It is better to use === and !==, which do not do type coercion.

2. Never use With statement in JavaScript

It is ambiguous.Please check this blog for details

3. Avoid using Eval statement in JavaScript

The only exception is when you parse JSON.However, you need to completely trust your server which you should not.

There are several JSON parser you can find in JSON

Most recent browser (at the time of writing IE8,FireFox 3.5,Chrome 3) support native JSON Parsing.For more info, Check here

4. The number type in JavaScript is 64-bit floating point (aka “Double”)

0.1+0.2!==0.3

0.1 + 0.2 = 0.30000000000000004

5. Style Isn’t Subjective

block{

}

Works well in JavaScript

block

{

}

Might work well in other languages but not in JavaScript.

Check this ppt slides for details.

6. Use jslint to QA your JavaScript.

Useful links

Video Tutorial

JavaScript: The Good Parts

http://google-code-updates.blogspot.com/2009/03/doug-crockford-javascript-good-parts.html

The JavaScript Programming Language

http://yuiblog.com/blog/2007/01/24/video-crockford-tjpl/

An Inconvenient API: The Theory of the Dom

http://yuiblog.com/blog/2006/10/20/video-crockford-domtheory/

http://www.yuiblog.com/blog/2007/01/24/video-crockford-tjpl/
http://yuiblog.com/blog/2006/11/27/video-crockford-advjs/

Advanced JavaScript

http://yuiblog.com/blog/2006/11/27/video-crockford-advjs/

JavaScript

http://www.crockford.com/

http://www.json.org/

Asp.net and jQuery

http://encosia.com/

http://west-wind.com/Weblog/default.aspx

http://mattberseth.com/blog/jquery/

http://enterprisejquery.com/2010/10/how-good-c-habits-can-encourage-bad-javascript-habits-part-1/

kick it on DotNetKicks.com

About these ads
Categories: javascript
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 163 other followers

%d bloggers like this: