HOLLA TECH - LEARN

JavaScript Objects
 

JavaScript variables are containers for data values. Objects are variables too, but they can contain many values.

Think of an object as a list of values that are written as name:value pairs, with the names and the values separated by colons.
Example: 

var person = {
name: “John”, age: 31,
favColor: “green”, height: 183
}; 

  

These values are called properties.

Holla Tech - Learn JavaScript 

NOTE!
JavaScript objects are containers for named values.

Object Properties
 

You can access object properties in two ways.

objectName.propertyName
//or
objectName[‘propertyName’]

 

This example demonstrates how to access the age of our person object.

var person = {
name: “John”, age: 31,
favColor: “green”, height: 183
};
var x = person.age;
var y = person[‘age’]; 

 

JavaScript’s built-in length property is used to count the number of characters in a property or string. 

var course = {name: “JS”, lessons: 41};
document.write(course.name.length);
//Outputs 2 

 

NOTE!
JavaScript objects are containers for named values.

Object Methods [/su_quote] 

An object method is a property that contains a function definition.

Use the following syntax to access an object method.

objectName.methodName() 

 

As you already know, document.write() outputs data. The write() function is actually a method of the document object.

document.write(“This is some text”); 

 

NOTE!
Methods are functions that are stored as object properties.

BACK NEXT

CLICK ON THE BUTTON BELOW TO GO TO THE JAVASCRIPT MAIN COURSE PAGE. 

JAVASCRIPT MAIN COURSE PAGE

 


© License: All Rights Reserved 


CONTACT HOLLA TECH – LEARN SUPPORT