Objects are the most interesting and feature-rich data type in JavaScript. It can be used to store information (a set of heterogeneous data) about an object in the real world, such as a Hexlet user. A Hexlet user may be characterized as having an email, name, password, and other parameters. All of this can be "packed" into one object.
// The syntax will be explained in the next lesson
const user = {
email: 'inna@example.com',
name: 'Inna',
password: 'qwerty',
};
The contents of the package.json file can also be represented as a JavaScript object. Moreover, the name JSON itself stands for JavaScript Object Notation:
// json is the representation of an object as text
const data = {
name: 'MyProjectName',
description: "My Projects's Description",
dependencies: [
// here we have dependencies
],
// here we have the other properties
};
And finally, as hard as it may be to believe, functions and arrays in JavaScript are also objects.
typeof []; // object
// Functions are a little more complicated
// Checking if the function is an object
Math.random instanceof Object; // true
Objects in JavaScript permeate the whole of development from start to finish. They are ubiquitous and used in real-world applications, often for several purposes at once. They are used both as associative arrays (storing key-value pairs) and as objects in the sense of object-oriented programming, which we will definitely get to know later.
Knowing how to work with objects in JavaScript is a skillset basis that enables novice programmers to solve pretty complex problems. In this course, there will be a gradual introduction to objects and their capabilities. We'll cover the syntax, real-world use cases, and operators and look at the concept of destructuring and ways to traverse object properties in a loop.
Are there any more questions? Ask them in the Discussion section.
The Hexlet support team or other students will answer you.
For full access to the course you need a professional subscription.
A professional subscription will give you full access to all Hexlet courses, projects and lifetime access to the theory of lessons learned. You can cancel your subscription at any time.