View Full Version : trying to learn javascript. Not much sucess.

06-14-2007, 04:47 AM
Ok, very recently I've begun reading about javascript, because I would like to be able to generate some minor special effects to work under conditions where certain javascript isn't permitted. Normally I would just integrate scripts created by others(a million thanks to them), but much of it isn't permitted.

The problem is, I can't find some decent well written information that's usable for someone who has no programming background whatsoever. I can't believe that something that utilizes logic that a child in grade school could understand and explain in plain english, could be so obscured by such convoluted, half baked, and incompetent 'teaching'.

Is there some one than can describe the basic grammar of javscript for me?

06-14-2007, 05:12 AM
This is a pretty basic introduction - http://w3schools.com/js/default.asp

06-14-2007, 06:05 AM
Okay I have a specific questions, there are a few things that I find are never explained.

Do periods always and only separate objects and methods?

what exactly is the role of curly brackets "{}"?

What exactly are arguments? Where can they go, what do they apply to? Does it work like object.method(argument)?

What exactly is the role of the two rounded brackets "()"? What can they contain what can't they etc, etc?

For example, this confuses me:


Document is the object, write is a method...or a property? If it's not a property what is a property? Regardless of which it is, is it always followed by the rounded brackets as seen after toUpperCase? If write is a method, is txt a property of write? Does that mean properties only follow methods?

txt.toUpperCase just looks like another object and method, but is it? if it isn't how the heck am I supposed to tell the difference?...nobody explains this!

Gah, in this one line there is so much unexplained, but the tutorial just moves on like I'm supposed to know it. As usual the basic building blocks arent clearly defined before they start slapping things together.

06-14-2007, 07:28 AM
1. Periods can either separate objects from methods or be a character in a string.
Some languages use them for string concatenation, but not javascript.

2. Curly brackets (braces) separate "blocks" of code which logically fit together. For instance, a looping construct might look like this

Where the braces "clump together" all the actions which need to be looped.

3. Arguments are anything passed to a method or a function. Like this




All methods and functions have signatures which tell you what sort of arguments need to be passed in for the method to work properly which will look like - function(int i, int j);
That's just an example though, it's not always 2 integers.

4. Round brackets (parenthesis) have 2 purposes depending on the context. They can either contain the arguments being passed into a function/method, or they change the precedence order of operators (just like in math).
Like the statement x = 5 * 3 - 7 would result in 8 but x = 5 * (3 - 7) would result in -20.
This is also useful when dealing with a combination of floating point and integer operations.

5. document.write(txt.toUpperCase()); is writing a string to the screen. Presumably txt is a variable which contains a string. The function toUpperCase() is being executed on the string txt. Then the whole thing is being passed to the function document.write(); (and yes, document is the object being acted on and write is the method). Unless you see binary operators hanging around (+,-,*,/,% a few more) parenthesis can almost always be assumed to contain the arguments to a method/function.
txt is indeed another object - it's a string object. Just think of object like special large beefy primitive variables (although they are not by any means).
An integer might contain the number 7, but an object might contain the number 7 and the number 8.5 and some operations (methods) to manipulate those numbers.

6. I would suggest looking up on the basics of programing before becoming frustrated with the intricacies of a specific language. Once you understand what programming is really all about, the rest is just syntax.

06-14-2007, 08:10 AM
I wish the authors of most tutorials were as explicit as you were, though I could still drown you in a million questions.

So the parenthesis indicate the order hierarchy of what is completed before it's passed onto the next stage and it goes from left to right?

So basically you have the structure "object.method(argument)" that can be repeated infinitely within itself as each argument is actually just another object.method set that is performed before it's passed on to the object.method to it's left?

it's basically


and so on?

When does the content contained in braces come in then, or am i way off?

If it's required that I make this a full fledged programming education just to pick up some javascript, I'm not sure that it's worth it, but i'll look around for some general programming stuff.

Philip M
06-14-2007, 08:50 AM
Try and get hold of a book called "JavaScript in Easy Steps" by Mike McGrath.
Published Computer Step www.ineasysteps.com.
It is an excellent beginner's instruction book, and I am sure will answer all your questions. (Third Edition April 2006 is 10.99 - but available from Amazon and bookshops across the world).

06-14-2007, 08:56 AM
It's not actually infinite many object.method(object.method(object.method)));
Remember, an object is just another variable. You could just as easily say document.write(7); as document.write(txt.toUpperCase()); It all depends on what you want to do and on what is in the function signature. You could also say something like document.write(txt); which would write the text to screen without making it upper case first.

06-14-2007, 10:55 AM
Also you need to remember that document.write() is deprecated and should not be used at all. If you want to update the web page you should use the appropriate DOM commands or innerHTML.

06-14-2007, 09:17 PM
I'll check out that book.

So, an object is either a variable predefined by the language designers and held in an a 'dictionary' within the browser for reference, or a variable defined by you which is referenced within the document, and methods are actions that can be taken on that objects properties, so properties have to be predefined also?

How do you define properties then...? How do you define methods or are methods only definable by the language designers...?

The foundation structure is essentially Object.method(argument) and the argument structure can simply be (object), in which case it ends and is passed on to the left, or continued by following with a method that influences that objects predefined properties?

I've got a feeling I'm wandering further off the path with every step.


06-14-2007, 09:33 PM
object.property <-- note no ()