JavaScript Object and Method

Objective
In this lesson, students will learn:

  • how to start working with JavaScript objects and methods

An object is a collection of properties (related data and/or functionality (which usually consists of several variables and function)s — which are called properties and methods when they are inside objects.)

Syntax

Example

Properties are variables that belong to objects. You can give them any name you like. and any values: numbers, strings, Booleans, arrays, or even other objects. But unlike variables, a value is assigned with a colon, not an equal sign.

Use the object name, then a dot, and then the property you want to access. Use them like any other variables.

Example

Another format to create an object:

Object Methods
A method is a function which is a property of an objectA method is another name for a function inside an object.

Syntax

Example


References
JavaScrip Objects Basic
Method definitions

Advertisements