-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjects.js
More file actions
43 lines (29 loc) · 835 Bytes
/
objects.js
File metadata and controls
43 lines (29 loc) · 835 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const student = {
firstName: "Daniel",
lastName: "Lancheros",
age: 33,
student: true,
}
console.log(student.firstName)
// --lets get a bit more advanced
// Creating an object from seperate variables:
const make = "Mazda"
const model = "CX5" //variables
const year = 2022
const myCar = {make,model,year} // assembled 3 variables into a single object
// Frequently, we have an object and we want to break it into seperate variables
// *** This is called "destructuring". ***
// we have an object:
const movie = {
title: "Fight Club",
year: 1999,
writer: "Chuck P",
genre: "Action",
}
// lame way:
//const title = movie.title
//const writer = movie.writer
//const genre = movie.genre
// or we can write it awesome
const {title,writer,genre} = movie
console.log(movie.title) // Fight Club