We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 62156f2 commit 669aee5Copy full SHA for 669aee5
OptionalChaining.js
@@ -5,10 +5,24 @@ const user = {
5
street:" Road ",
6
city : "Patna" ,
7
state : "Bihar",
8
- zip : 4657890
9
-
10
- }
11
+ zip : 4657890
+ }
12
}
13
14
console.log(user.address.country?.pin); //undefined
+
+//Optional chaining can be used to acess the elements of the array in JavaScript . It works in a similar way to acessing properties
+// of an object but using ?.[] instead of the ?. operator
15
16
+const users = [
17
+ {name : "Riya" , age: 20 },
18
+ {
19
+ name : "bebe" , age : 25},
20
21
+ name : "jenny", age : 30} ,
22
+ ];
23
24
+console.log(users[3]?.age);
25
26
27
28
0 commit comments