Expand my Community achievements bar.

Using Optional Chaining in Custom Code

Avatar

Level 1

I am trying to use optional chaining in the custom code part of a rule. It tells me that Optional chaining' is only available in ES11 (use 'esversion: 11').
I have looked in the documentation and tried to figure out how to do this but i am stuck. If i could get pointed in the right direction or something to enable optional chaining in the custom code section i would appreciate it.

2 Replies

Avatar

Community Advisor

Firstly, don't link to a AEP Tags URL. None of us can open it since we're not users in your Tags product. 

The warning that you see with your custom code is shown because optional chaining is, as you've noted, available with ES11 and above. However, by design, Tags wants to support as many browsers as possible because such browsers are still being used publicly.

If you think that all of your website users use browsers that support optional chaining, then you can ignore that warning and use your code. Your library will still get built (and published) properly. (You can use your analytics product to check the browsers that you website users use.)

If you don't want to use optional chaining, then you can go back to the old way of checking that your object's properties are "truthy", e.g.

var obj;
if (obj.key) {
  // do something with obj.key
}

Avatar

Level 1

Thanks for the information! I will remember that moving forward.