What is the obj?.prop syntax in javascript? [duplicate]





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







9
















This question already has an answer here:




  • Null-safe property access (and conditional assignment) in ES6/2015

    9 answers




I was looking through a code and I came across this:



{{abc?.xvy=== tyu?abc?.xz:abc?.xz}}


I am unable to understand meaning of this expression. I know that it is Null-safe property access but I am bit confused about the chaining.
Any help is much appreciated










share|improve this question















marked as duplicate by adiga, Samuel Liew javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Feb 5 at 7:54


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • I hope this code isn't used anywhere.

    – Eric Duminil
    Feb 5 at 7:39











  • unfortunately I saw it is used. Why is it not supposed to be used ?

    – Apurva Pathak
    Feb 5 at 8:56











  • It really isn't readable at all, abc, xvy tyu are too generic to be useful and the ternay operator is useless because both outcomes are the same, as mentioned here

    – Eric Duminil
    Feb 5 at 8:57


















9
















This question already has an answer here:




  • Null-safe property access (and conditional assignment) in ES6/2015

    9 answers




I was looking through a code and I came across this:



{{abc?.xvy=== tyu?abc?.xz:abc?.xz}}


I am unable to understand meaning of this expression. I know that it is Null-safe property access but I am bit confused about the chaining.
Any help is much appreciated










share|improve this question















marked as duplicate by adiga, Samuel Liew javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Feb 5 at 7:54


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • I hope this code isn't used anywhere.

    – Eric Duminil
    Feb 5 at 7:39











  • unfortunately I saw it is used. Why is it not supposed to be used ?

    – Apurva Pathak
    Feb 5 at 8:56











  • It really isn't readable at all, abc, xvy tyu are too generic to be useful and the ternay operator is useless because both outcomes are the same, as mentioned here

    – Eric Duminil
    Feb 5 at 8:57














9












9








9


1







This question already has an answer here:




  • Null-safe property access (and conditional assignment) in ES6/2015

    9 answers




I was looking through a code and I came across this:



{{abc?.xvy=== tyu?abc?.xz:abc?.xz}}


I am unable to understand meaning of this expression. I know that it is Null-safe property access but I am bit confused about the chaining.
Any help is much appreciated










share|improve this question

















This question already has an answer here:




  • Null-safe property access (and conditional assignment) in ES6/2015

    9 answers




I was looking through a code and I came across this:



{{abc?.xvy=== tyu?abc?.xz:abc?.xz}}


I am unable to understand meaning of this expression. I know that it is Null-safe property access but I am bit confused about the chaining.
Any help is much appreciated





This question already has an answer here:




  • Null-safe property access (and conditional assignment) in ES6/2015

    9 answers








javascript ecmascript-5






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 5 at 7:14







Apurva Pathak

















asked Feb 5 at 6:26









Apurva PathakApurva Pathak

1369




1369




marked as duplicate by adiga, Samuel Liew javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Feb 5 at 7:54


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by adiga, Samuel Liew javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Feb 5 at 7:54


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • I hope this code isn't used anywhere.

    – Eric Duminil
    Feb 5 at 7:39











  • unfortunately I saw it is used. Why is it not supposed to be used ?

    – Apurva Pathak
    Feb 5 at 8:56











  • It really isn't readable at all, abc, xvy tyu are too generic to be useful and the ternay operator is useless because both outcomes are the same, as mentioned here

    – Eric Duminil
    Feb 5 at 8:57



















  • I hope this code isn't used anywhere.

    – Eric Duminil
    Feb 5 at 7:39











  • unfortunately I saw it is used. Why is it not supposed to be used ?

    – Apurva Pathak
    Feb 5 at 8:56











  • It really isn't readable at all, abc, xvy tyu are too generic to be useful and the ternay operator is useless because both outcomes are the same, as mentioned here

    – Eric Duminil
    Feb 5 at 8:57

















I hope this code isn't used anywhere.

– Eric Duminil
Feb 5 at 7:39





I hope this code isn't used anywhere.

– Eric Duminil
Feb 5 at 7:39













unfortunately I saw it is used. Why is it not supposed to be used ?

– Apurva Pathak
Feb 5 at 8:56





unfortunately I saw it is used. Why is it not supposed to be used ?

– Apurva Pathak
Feb 5 at 8:56













It really isn't readable at all, abc, xvy tyu are too generic to be useful and the ternay operator is useless because both outcomes are the same, as mentioned here

– Eric Duminil
Feb 5 at 8:57





It really isn't readable at all, abc, xvy tyu are too generic to be useful and the ternay operator is useless because both outcomes are the same, as mentioned here

– Eric Duminil
Feb 5 at 8:57












3 Answers
3






active

oldest

votes


















4














Its new ES proposal called "optionals" for safe check reading for object properties. Above expression is equivalent to:



(abc && abc.xvy) === (tyu) ? (abc && abc.xz) : (abc && abc.xz)


You can find more details here: https://github.com/davidyaha/ecmascript-optionals-proposal






share|improve this answer





















  • 2





    OP's code doesn't have any standalone reference to an xz variable, though.

    – CertainPerformance
    Feb 5 at 7:17











  • (tyu) ? (abc && abc.xz) : (abc && abc.xz) is just abc && abc.xz

    – Eric Duminil
    Feb 5 at 12:34



















7














This looks to be an example of the optional chaining proposal, which is still very much a work in progress (only at Stage 1). It's not actually implemented in vanilla JS environments yet. Using



obj?.prop


means: if obj is undefined or null, the expression evaluates to undefined. But otherwise, it will evaluate to the prop property on the object. This is syntax sugar for



obj && obj.prop


(using just obj.prop alone will throw if obj is undefined or null)



So, your



abc?.xvy=== tyu?abc?.xz:abc?.xz


will evaluate to true if the nested value abc?.xvy is equal to the nested value abc?.xz - or, it will evaluate to true if at least one of the nested values doesn't exist, and the other is undefined.



Spaced out for easier reading:



abc?.xvy === tyu
? abc?.xz
: abc?.xz


As you can see, both ? and : expressions are the same, making the conditional operator unnecessary here. An equivalent test (assuming that referencing tyu doesn't throw) would be



abc?.xvy === abc?.xz





share|improve this answer































    4














    It's called Null Propagation Operator.



    We can think of each ?. operator as a short circuit where "if the expression up until this point is null or undefined, then the whole expression evaluates to undefined".
    We could also optionally call functions.






    share|improve this answer






























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      4














      Its new ES proposal called "optionals" for safe check reading for object properties. Above expression is equivalent to:



      (abc && abc.xvy) === (tyu) ? (abc && abc.xz) : (abc && abc.xz)


      You can find more details here: https://github.com/davidyaha/ecmascript-optionals-proposal






      share|improve this answer





















      • 2





        OP's code doesn't have any standalone reference to an xz variable, though.

        – CertainPerformance
        Feb 5 at 7:17











      • (tyu) ? (abc && abc.xz) : (abc && abc.xz) is just abc && abc.xz

        – Eric Duminil
        Feb 5 at 12:34
















      4














      Its new ES proposal called "optionals" for safe check reading for object properties. Above expression is equivalent to:



      (abc && abc.xvy) === (tyu) ? (abc && abc.xz) : (abc && abc.xz)


      You can find more details here: https://github.com/davidyaha/ecmascript-optionals-proposal






      share|improve this answer





















      • 2





        OP's code doesn't have any standalone reference to an xz variable, though.

        – CertainPerformance
        Feb 5 at 7:17











      • (tyu) ? (abc && abc.xz) : (abc && abc.xz) is just abc && abc.xz

        – Eric Duminil
        Feb 5 at 12:34














      4












      4








      4







      Its new ES proposal called "optionals" for safe check reading for object properties. Above expression is equivalent to:



      (abc && abc.xvy) === (tyu) ? (abc && abc.xz) : (abc && abc.xz)


      You can find more details here: https://github.com/davidyaha/ecmascript-optionals-proposal






      share|improve this answer















      Its new ES proposal called "optionals" for safe check reading for object properties. Above expression is equivalent to:



      (abc && abc.xvy) === (tyu) ? (abc && abc.xz) : (abc && abc.xz)


      You can find more details here: https://github.com/davidyaha/ecmascript-optionals-proposal







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Feb 5 at 7:19

























      answered Feb 5 at 6:33









      Vishal RajoleVishal Rajole

      844816




      844816








      • 2





        OP's code doesn't have any standalone reference to an xz variable, though.

        – CertainPerformance
        Feb 5 at 7:17











      • (tyu) ? (abc && abc.xz) : (abc && abc.xz) is just abc && abc.xz

        – Eric Duminil
        Feb 5 at 12:34














      • 2





        OP's code doesn't have any standalone reference to an xz variable, though.

        – CertainPerformance
        Feb 5 at 7:17











      • (tyu) ? (abc && abc.xz) : (abc && abc.xz) is just abc && abc.xz

        – Eric Duminil
        Feb 5 at 12:34








      2




      2





      OP's code doesn't have any standalone reference to an xz variable, though.

      – CertainPerformance
      Feb 5 at 7:17





      OP's code doesn't have any standalone reference to an xz variable, though.

      – CertainPerformance
      Feb 5 at 7:17













      (tyu) ? (abc && abc.xz) : (abc && abc.xz) is just abc && abc.xz

      – Eric Duminil
      Feb 5 at 12:34





      (tyu) ? (abc && abc.xz) : (abc && abc.xz) is just abc && abc.xz

      – Eric Duminil
      Feb 5 at 12:34













      7














      This looks to be an example of the optional chaining proposal, which is still very much a work in progress (only at Stage 1). It's not actually implemented in vanilla JS environments yet. Using



      obj?.prop


      means: if obj is undefined or null, the expression evaluates to undefined. But otherwise, it will evaluate to the prop property on the object. This is syntax sugar for



      obj && obj.prop


      (using just obj.prop alone will throw if obj is undefined or null)



      So, your



      abc?.xvy=== tyu?abc?.xz:abc?.xz


      will evaluate to true if the nested value abc?.xvy is equal to the nested value abc?.xz - or, it will evaluate to true if at least one of the nested values doesn't exist, and the other is undefined.



      Spaced out for easier reading:



      abc?.xvy === tyu
      ? abc?.xz
      : abc?.xz


      As you can see, both ? and : expressions are the same, making the conditional operator unnecessary here. An equivalent test (assuming that referencing tyu doesn't throw) would be



      abc?.xvy === abc?.xz





      share|improve this answer




























        7














        This looks to be an example of the optional chaining proposal, which is still very much a work in progress (only at Stage 1). It's not actually implemented in vanilla JS environments yet. Using



        obj?.prop


        means: if obj is undefined or null, the expression evaluates to undefined. But otherwise, it will evaluate to the prop property on the object. This is syntax sugar for



        obj && obj.prop


        (using just obj.prop alone will throw if obj is undefined or null)



        So, your



        abc?.xvy=== tyu?abc?.xz:abc?.xz


        will evaluate to true if the nested value abc?.xvy is equal to the nested value abc?.xz - or, it will evaluate to true if at least one of the nested values doesn't exist, and the other is undefined.



        Spaced out for easier reading:



        abc?.xvy === tyu
        ? abc?.xz
        : abc?.xz


        As you can see, both ? and : expressions are the same, making the conditional operator unnecessary here. An equivalent test (assuming that referencing tyu doesn't throw) would be



        abc?.xvy === abc?.xz





        share|improve this answer


























          7












          7








          7







          This looks to be an example of the optional chaining proposal, which is still very much a work in progress (only at Stage 1). It's not actually implemented in vanilla JS environments yet. Using



          obj?.prop


          means: if obj is undefined or null, the expression evaluates to undefined. But otherwise, it will evaluate to the prop property on the object. This is syntax sugar for



          obj && obj.prop


          (using just obj.prop alone will throw if obj is undefined or null)



          So, your



          abc?.xvy=== tyu?abc?.xz:abc?.xz


          will evaluate to true if the nested value abc?.xvy is equal to the nested value abc?.xz - or, it will evaluate to true if at least one of the nested values doesn't exist, and the other is undefined.



          Spaced out for easier reading:



          abc?.xvy === tyu
          ? abc?.xz
          : abc?.xz


          As you can see, both ? and : expressions are the same, making the conditional operator unnecessary here. An equivalent test (assuming that referencing tyu doesn't throw) would be



          abc?.xvy === abc?.xz





          share|improve this answer













          This looks to be an example of the optional chaining proposal, which is still very much a work in progress (only at Stage 1). It's not actually implemented in vanilla JS environments yet. Using



          obj?.prop


          means: if obj is undefined or null, the expression evaluates to undefined. But otherwise, it will evaluate to the prop property on the object. This is syntax sugar for



          obj && obj.prop


          (using just obj.prop alone will throw if obj is undefined or null)



          So, your



          abc?.xvy=== tyu?abc?.xz:abc?.xz


          will evaluate to true if the nested value abc?.xvy is equal to the nested value abc?.xz - or, it will evaluate to true if at least one of the nested values doesn't exist, and the other is undefined.



          Spaced out for easier reading:



          abc?.xvy === tyu
          ? abc?.xz
          : abc?.xz


          As you can see, both ? and : expressions are the same, making the conditional operator unnecessary here. An equivalent test (assuming that referencing tyu doesn't throw) would be



          abc?.xvy === abc?.xz






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Feb 5 at 6:35









          CertainPerformanceCertainPerformance

          97.5k165887




          97.5k165887























              4














              It's called Null Propagation Operator.



              We can think of each ?. operator as a short circuit where "if the expression up until this point is null or undefined, then the whole expression evaluates to undefined".
              We could also optionally call functions.






              share|improve this answer




























                4














                It's called Null Propagation Operator.



                We can think of each ?. operator as a short circuit where "if the expression up until this point is null or undefined, then the whole expression evaluates to undefined".
                We could also optionally call functions.






                share|improve this answer


























                  4












                  4








                  4







                  It's called Null Propagation Operator.



                  We can think of each ?. operator as a short circuit where "if the expression up until this point is null or undefined, then the whole expression evaluates to undefined".
                  We could also optionally call functions.






                  share|improve this answer













                  It's called Null Propagation Operator.



                  We can think of each ?. operator as a short circuit where "if the expression up until this point is null or undefined, then the whole expression evaluates to undefined".
                  We could also optionally call functions.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Feb 5 at 6:34









                  Alex ParkAlex Park

                  907




                  907















                      Popular posts from this blog

                      Сан-Квентин

                      Алькесар

                      Josef Freinademetz