Objects

JavaScript can be used to define objects. These objects act like classes in that they contain properties and methods. Like other languages, you use objects in JavaScript to make your code more readable, easier to understand, and thus more maintainable. There are two primary ways to create objects in JavaScript: using the literal notation, and using the object construction notation. Let’s look at each.

Literal Notation

You create an object using the literal notation by assigning a variable as the object name and then using brackets to contain the properties and method for the object. Each property and method is defined using a colon and separated by a comma. The methods are defined as a function. The following shows an object created ...

Get Microsoft Visual Studio 2015 Unleashed, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.