JSFiddle - React, Tailwind, and code Playground

by Andrew Bone

HTML

<span class="text1"></span>
<span class="text2"></span>

JavaScript

const object = {
  prop1: {
    prop2: {
      prop3: {
      	text: "hello"
      }
    }
  }
}

// No errors even though prop4 doesn't exist.
document.querySelector('.text1').textContent = object?.prop1?.prop2?.prop3?.text;
document.querySelector('.text2').textContent = object?.prop1?.prop2?.prop3?.prop4;