JavaScript | Programming | Decisions | Objects
Javascript is an object-orientated programming language. Everything in JavaScript is treated as an object. An object, like an array, is basically any collection of names and values, also known as properties and methods. Properties are variables local to the object. Methods are functions local to the object. An object serves as a template, which instances can be called for use of its properties or methods. Objects are built-in or they can be created.
A common built-in object is the document object, which refers to the JavaScript file itself. Properties and/or methods are added with dot syntax. The following example appends the write() method to the document object while passing a variable...
Creating an object is similar to creating a function. The function command declares a new object, followed by the name of the object. Objects are created with the same naming conventions as a variable. The object definition is declared within { } side brackets. Properties are stored in variables. The this command references the variable. The var command declares a variable within the object. The new command calls an object, storing it in a new variable. The new variable becomes the instance of the object.
The output is...
This is a value.
The following example declares a method and passes parameters to the object...
The output is...
Name: Jeff
City: Vancouver