Javascript n00b part 1

singingfish on 2007-04-24T04:49:34

Unfortunately, javascript is a pain, but getting better. Unfortunately there seem to be a few good books out there, and none of them in my local library. Time to create my own resource for learning javascript! WTFM indeed. So following the advice of people who know, I downloaded the Core Javascript Guide. To give myself an interactive environment for learning Javascript I downloaded Firebug and off we go.

First up is the chapter on variables. Open up the Firebug inspector (a green tick in the lower rhs of my browser here) and declare a string in the interaction line (right at the bottom of the window with three blue angle brackets (>>>) like so:

a = "Hi";

Then: window.alert(a);

There we go, scalar variable naming and browser interactivity all in one go. Next up the rest of the chapter.

BTW while this isn't directly relevant to Catalyst, people do pop up on IRC asking for the "best javascript book" and the approach above seems a reasonable substitute.

Update: I found the little gray V at the far right hand side of the firebug eval area in firebug. Turns out you can eval blocks of code too :) :

a = 'foo'; b= 'bar'; if (a == 'foo' && b != 'bar') { window.alert(a)} else { window.alert(b) }

Update: (again). A little birdie tells me that I should declare my variables with var a = 'Hi'. Something to do with scoping issues. I guess once I understand how to do data structures in javascript I'll be working out scope and how to do something "use strict" like.


Read Pro JavaScript Techniques

tomhukins on 2007-04-24T11:14:35

If you're already comfortable writing in a language like Perl, you will find Pro JavaScript Techniques a good guide to JavaScript.