Thank you for the replay.
I found out what was the problem - in the type of the variable.
If I set the var or const from the collection variables, it is not a string but any - so that the length property cannot be used.
I need to re-type it to string first.
This is working:
var someValue = pm.collectionVariables.get("Var01").toString();
console.log(someValue.length);