|
#1
|
|||
|
|||
|
Okay. So i've been reading up, and I am going to be coming here with my random questions. Instead of making a new thread that can be answered in one post for every question i come across, I'm going to start posting them all in here.
Question #1 - Arrays so you can make an array by using the following syntax Code:
var a = new Array();
a[0] = 1;
a[1] = 2;
a[2] = 3;
First of all, if you try to find the lenth of the array, what will it tell you? Since you didn't define the length when you created the array, does it even have a length? What if you try assigning something to like the 400th element in the array without assigning something to the other 399 elements? Will it go ahead and let you do that? Thanks. |
|
#2
|
||||
|
||||
|
Quote:
Quote:
__________________
-Brady |
|
#3
|
|||
|
|||
|
so if i do a loop to display all elements from 0 - 400, it would display undefined up until 400?
|
|
#4
|
||||
|
||||
|
It would output:
1 2 3 undefined undefined undefined undefined undefined ... and so on. Another thing to note is that .length is the highest index in the array plus one. So: Code:
var a = []; a[0] = "a"; a[13] = "m";
__________________
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP! |
|
#5
|
|||
|
|||
|
ahhh i get it. thanks for clearing that up. More questions to come.
|
|
#6
|
|||
|
|||
|
Question #2 - Variable scopes
Say you are making a for loop. Code:
for(i = 0; i < 10; ++i)
{
documment.write(i);
}
|
|
#7
|
|||
|
|||
|
Question #3 - this. and document.
So when are each of these used? How do I know that it should be document.bgColor = 'red'; instead of this.style.bgColor = 'red'; or something? |
|
#8
|
||||
|
||||
|
Quote:
A note on scope in Javascript: I know you are proficient with Java, and one common mistake people often make when moving to Javascript from Java and similar C-like languages is to assume that a code block denotes a new scope. This is not so in Javascript. Quote:
this, on the other hand, refers to the object containing a method. Inside document.getElementById(), for example (if it were written in Javascript, that is) this would refer to document. If a method doesn't belong to an object, this refers to the global object (window in the case of browsers). Event handlers are properties of their respective elements, so inside an event handler, this usually refers to the element that caught the event. Quote:
__________________
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP! |
|
#9
|
||||
|
||||
|
Quote:
|
|
#10
|
|||
|
|||
|
Question #4 - Adding .js files.
So I made a .js file to find imaginary numbers using a C++ program I made as a reference. I'm pretty sure it all works. Only problem is I am not really sure how to add it to the main page. I need something like an #include but for javascript. And when I want to test it out, I can use it just like any other function, right? |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
|
|