Using Optional Chaining in Custom Code | Community
Skip to main content
March 20, 2023
Question

Using Optional Chaining in Custom Code

  • March 20, 2023
  • 1 reply
  • 1398 views

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

yuhuisg
Community Advisor
Community Advisor
March 21, 2023

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 }
avswainAuthor
March 21, 2023

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