A Simple, Comprehensive Overview of Javascript

This isn’t a reference guide, programming tutorial or detailed overview. It’s a Javascript refresher, assuming you know another programming language and puts all the information in one place (just ctrl+f to find!). Javascript has nothing to do with Java, is dynamically typed and has **C-like syntax


This is a companion discussion topic for the original entry at http://betterexplained.com/articles/the-single-page-javascript-overview/

This is good. I like your spirit!

So we can use objects like associative arrays in php. Nice.

Yep, that’s a good point. I use javascript objects as a hash table (associative array) quite often.

[…] A bookmarklet can use any javascript command, but certain ones are helpful: […]

Yeaah it’s very simple and comprehensive Overview.

Thanks

var obj = { // create object using JSON
name: “Bob”, // aka Javascript Object Notation
details: {
age: 33,
“favorite color”: “green”
}
}
obj.name
obj.details[“favorite color”]

i’ve a question… how can I print all obj property without know them
exist something like reflection???
I’m looking for a function like (php) print_r(obj)

@Steal: You’d have to iterate through all the properties on the object and print them out:

for(prop in obj)
{
str += prop + “value :” + obj[prop]+"\n";
}

See http://vijayk.wordpress.com/2006/12/14/for-in-loop-to-print-object-properties-with-javascriptactionscript/

In line 4 of your sample for the section “Comparisons and Manipulations,” it seems to me that you’re missing a ‘=’.

@Anonymous: Whoops! Yep, you’re correct, fixed now. Thanks!

Thank you!
I am new to Javascript and you have given me good starting point. I find it so easy to follow JS now.

Thanks!

Thanks Samuel, great catch! Just updated to clarify.

These lines are not quite correct:

var str = “Hello”; // local variable
str2 = “Hello World”; /* global */

While “var” is the correct way to define a variable in the local scope, in this case both “str” and “str2” will become properties of the “window” object, which is essentially JavaScript’s global scope. A function is the only way to create a new local scope in JS, so “var” is only useful inside functions (and all JS code should be inside a function to prevent polluting the global scope).

When describing constructor functions you use self without defining it. Its probably better to just use this.

the redirect when JavaScript is disabled sounds like a pretty good idea, however I’ve heard before that meta redirects are viewed negatively by Google and other search engines. If you’re using PHP maybe you could do a redirect with that inside the noscript tag. (or whichever server side programming language you prefer.)
Nice to see such an article recently posted somewhere and up voted 6 years after it was originally published…

@devurls: Interesting point, not sure about the SEO impact. Yep, I like that this is still handy for people!

@Michael, Adam: Thanks, great feedback. Just changed.

In you “Javascript Classes” section, “self.setName” should be “this.setName”. Otherwise, a nice summary!

[…] http://betterexplained.com/articles/the-single-page-javascript-overview/ […]

Simply awesome man