Can't read JS variable

We have the case where each page has a JS variable like this:

var AB = AB || {}; AB.One = {Alpha: 'Hello', Beta: 'Welt'};

I want to read the value “Hello” into a custom JS variable in MTM like this:

…but it does not read the value. What am I doing wrong?

Okay, I solved this problem:

Can anybody tell me why AB.One['Alpha'] did not work? (Returned an empty string.)


That’s because that field doesn’t accept any valid JS expression, but explicitly just the name of a single JS variable (which AB.One['Alpha'] isn’t).
But AB.One.Alpha works, because that case is explicitly supported in the code as you can see in the Javascript that is executed when you create a JS variable in Tag Manager:

Hi @Lukas thanks a lot for your reply! In the meantime (one week after my post, but 4 hours before you wrote your explanation!) I reported this as a bug: [] javascript notation not accepted by MTM
So if I understand you correctly it’s not a bug. The tag manager has this help field:
Reading it again I understand it, but back then I did not understand it to exclude the [] notation. Maybe it’s obvious to anybody who is more familiar with JS. Or it would profit from explicitly ruling that out, like adding “Other notations like document[‘referrer’] are not accepted.”