Introducing object part 2

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'];
Try It Yourself

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
Try It Yourself

Objects are one of the core concepts in JavaScript.

Comments

Popular posts from this blog

String Operators

Introducing object part 3

The math object part 2