Assume we have a string unknownStr with an unknown value that is not undefined and not null.
Assume we then have this code:
var chrArray = [];
var keyValObject = {};
var keyLength;
for (var i = 0; i < unknownStr.length; i++) { chrArray.push(unknownStr[i]); }
for (var i = 0; i < chrArray.length; i++) { keyValObject[chrArray[i]] = "foo"; }
for (var key in keyValObject) { keyLength = key.length; }
Is it possible that keyLength will ever have a value other than 1?
Yes this is possible and can be demonstrated as follows
Now all objects will have the property
longKeyincludingkeyValObject. Because you don’t restrict thekeyvalue in theforloop tohasOwnPropertyit will eventually seelongKeywhich has a length greater than 1