JavaScript – The Good Parts

JavaScript has become the most important programming language in the world.
It’s the only language that people feel they don’t need to learn it before they start using it.

It’s also the world most misunderstood programming language.

Check the notes and remarks below and come back to see the video.

JS is becoming the virtual machine for the world. Used almost everywhere.

It’s a language of many contrasts. It contains both the ridiculous and the sublime.

The DOM is one of the worst API ever imagined. And because that’s what you use when you use browsers, people tend to blame JavaScript for faults caused by the DOM.

Global variables are by far the worst bad thing in JavaScript. Cross-Site Scripting attacks are fundamentally
enabled by global variables.

When it get a compilation error, it backs up, looks around for a line feed, replace it with a semicolon and tries again.
That should really freak you out.
Advice: Put yourself the semicolons where they’re supposed to be.

‘eval’ is the most misused feature in the language.

Dimensioning an array doesn’t exist in the language.

JavaScript support Type coercion, which is the conversion of one type of object to a new object of a different type with similar content.
This leads to surprising error and mistakes.
Always use the triple equal operator (===). Never use the double equal operator (==). Just don’t use it.

JavaScript Type Coercion

Type Coercion and funny mistakes

Be careful with errors that cancel each out.

Wrong code:

value = myObject[‘name’

if (value == null)
{// Do something}

Good code

….
if (value === undefined)
{// Do something}

Avoid blockless statements and always include curly braces !

Bad:
if (foo())
bar ();

Good:
if (foo())
{
bar();
}

JavaScript good parts are:
Lambdas: One of the best things to have happened to a programming language. It’s powerful, safe, smart.
Dynamic Objects: You can add or remove a new property to and from an object at any time.
Loose Typing.
Object literals: very nice notation to describe objects. Was the inspiration for JSON.

Closures are one of the best parts of JavaScript.

Prototypal inheritance is built-in into JavaScript. It’s class-free. Object directly inherit from other objects.
var newObject = Object.create(oldObject);

Be very careful with style when coding in JavaScript. Style isn’t subjective.

Style is not subjective

Style is not subjective

Here is another VERY good reason why Style is not subjective at all.

Style

Style is not subjective !!!


JSON
became a standard because Crockford said it was. At the time, some customers didn’t want to use JSON because they saud they had committed to XML for data interchange and JSON wasn’t a widely adopted standard. Doug said it was. Ad here we are.

JSLint is a code quality for JavaScript written by Crockford. It parses your program and analyzes it for weaknesses.

If you haven’t done it yet, check Doug. Crockford’s book on the subject.

JavaScript - The Good parts

Advertisements

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

%d bloggers like this: