- And so much more!
Objects are collections of properties, and properties are an association between a key and a value. In some cases, though, the value of a property is a function, making that property a method. The properties of an object usually describe the characteristics of its variable. For example, an Array has
.length to know how many elements are in them. The Math object has a
.PI property, in case you get hungry.
Methods behave differently, as they're functions that need to be called. They can be used to modify or convert a property of an object, perform an action, return a specific piece of information, and more. For example, if you've worked with a String, you may have called the
toUpperCase() method to get the string in complete upper case.
Likewise, with an Array, you could call
.sort() to sort the elements.
You can then instantiate a new instance of that object with
new and reuse it repeatedly.
This blog is inspired by one of our Twitter threads that we post on our Twitter account. There are many threads like this; you should check them out.