Second place for this is arrays. When I first learned arrays, I didn't understand their purpose. Not until I actually read the purpose. They are amazing, as they can hold many values. I suggest you do the same.
There are many ways to work with an array. The one purpose of it is to reduce the need for many variables, and instead create one variable with multiple values. Learn here (at W3Schools).
But I saved first place for last. It is even better. You can assign your own names to an object, as you may have learned. Think of a JS object as something like a tree. Let's assign three properties to it in the simplest way:
var tree={barkcolor:"gray",feet:"100",type:"oak"};
See that? This may save your coding day. You can get any of these properties in different ways. As though your retrieving the value of a regular variable. You can do something like this:
alert("The tree's bark is colored "+tree.barkcolor+".");
alert("The tree's bark is colored "+tree.barkcolor+".");
The coding above will display an alert box, and it will say this: The tree's bark is colored gray.
Just a tip. And can be highly useful.
Just a tip. And can be highly useful.
No comments:
Post a Comment
Please keep your comments appropriate.