How does JavaScript define array elements
This article mainly explains "how JavaScript defines array elements". Interested friends may wish to take a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how JavaScript defines array elements.
Define array elements, and finally cannot add commas
Although there is nothing wrong with the syntax of adding a comma after the last value of the array, different browsers may get different results.
Varcolors= [5, 6, 7,]; / / the length of such an array may be 3 or 4.
The correct way to define:
Points= [40,100,1,5,25,10]
Define an object, and finally you cannot add a comma
The wrong way to define:
Websites= {site: "Rookie tutorial", url: "www.runoob.com", like:460,}
The correct way to define:
Websites= {site: "Rookie tutorial", url: "www.runoob.com", like:460}
Undefined is not Null
In JavaScript, null is used for objects and undefined for variables, properties, and methods.
The object can be null only if it is defined, otherwise it is undefined.
If we want to test whether the object exists, an error will be thrown when the object is not defined.
The wrong way to use:
If (myObjective people = "undefined")
The correct way is that we need to first use typeof to detect whether the object is defined:
If (typeofmyObjackers) = "undefined" & & myObjackers are null)
Block scope
JavaScript does not create a new scope in each code block, and the scope of each code block is generally global.
The variable I of the following code returns 10 instead of undefined:
Example
For (var I = 0; I < 10; iTunes +) {
/ / some code
}
Return i
At this point, I believe you have a deeper understanding of "how JavaScript defines array elements". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!