Conditional rendering in React based on if the variable is defined or not

Here we have used conditional rendering to prevent our code from breaking if the my_object variable is undefined.

import React from "react"

function MyComponent() {

    // Note the ? operator, it tells that property may or may not be present.
    let my_object = somethinghere.somechild?.moredeeper?.evenmoredeep

    return (
                my_object && (

export default MyComponent

the above code works, because in JS, true && expression always evaluates to expression, and false && expression always evaluates to false.