Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

optional chaining in js

// Optional chaining

// Basically Optional chaining is use nested destructuring like shown below !!

// const obj = [{
//  obj: {
//   obj: "FAhad",
//  },
//}]

// console.log(obj[0]?.obj?.obj);

// Like as you watched that How we are getting the elements from obj

const obj = [{
  obj: {
  },
}]

console.log(obj[0]?.obj?.obj);

// It's retruning undefined just because of optional chaining otherwise it'll return an error 

// ----------THE END----------
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #optional #chaining #js
ADD COMMENT
Topic
Name
4+6 =