Do you know ?. this symbol? What is the difference between ?? and ?. in JavaScript

 

Foreword:

        you know?. this symbol

For example, some objects have children as an array, and some objects have children as null. For example, some objects have children as an array, and some objects have children as null.

Null coalescing symbol  ??

 Only when the left side is null and undefined, the number on the right side will be returned

const too = null ?? 'default string'

// default string

?. optional operator

Does not raise an error if the reference is null or undefined,

const adventurer = {
    name :'abc',
    cat:{
        name:'maomi'
    }
}


const dogName = adventurer.dog?.name

console.log(dogName)  // unidefine

My brain is full of knowledge~

Guess you like

Origin blog.csdn.net/zhangxueyou2223/article/details/130953581