Under what circumstances will the condition above be met?
The condition will be satisfied when the variable obj is a String object and the variable key has a value like '12'. In the original poster's code, obj is an Object so the comparison fails at type === '[object String]'
When would it be skipped?
The condition will be skipped whenever the variable type is not equal to '[object String]' or if the key does not consist of only digits. A valid value that would pass this test could be a string like '12', '12345', or '0'.
If a JSON object were to pass, how would that condition match?
I am uncertain about the meaning of your question. :-(
If obj contains a value such as '12', then in the following expression:
for (var key in obj)
obj is temporarily converted into an object as though by using new String(obj)
(the String constructor is utilized because the Type of obj is a string). This object now has two keys: '0' and '1' with respective properties '1' and '2'. Therefore, the condition:
if (type === '[object String]' && number.test(key))
will evaluate to true because the object is a String and its keys are numeric. Since there are no non-numeric, enumerable keys, the loop encounters the continue statement resulting in no further action within the loop. For instance:
var obj = '12';
var type = Object.prototype.toString.call(obj);
var number = /^\d+$/;
for (var key in obj) {
// This condition applies to both keys
if (type === '[object String]' && number.test(key)) {
console.log(key); // Outputs 1 and 2
continue;
}
//additional code here
}
In case obj represents anything other than a String, the "additional code" section will execute.