Question: In this code fragment

```
foreach (var row in grid.Rows) { }              

```

the type of row is inferred as Object instead of GridViewRow. I have to explicitly declare the type to work with a GridViewRow:

```
foreach (GridViewRow row in grid.Rows) { }

```

GridView.Rows returns a GridViewRowCollection and GetEnumerator on the collection "Returns an enumerator that contains all GridViewRow objects in the GridViewRowCollection." If I access a single row from the collection by index

```
var row = grid.Rows[0];

```

the type is correctly inferred. Why can't the compiler infer the type for row in the foreach declaration?

Edited to add: Interesting responses, I didn't think to look for the obvious problem. ListView.Items implements `IList<ListViewDataItem>`, so this looks like an oversight to me.

Answer: 
Checking for undefined-ness is not an accurate way of testing whether a key exists. What if the key exists but the value is actually `undefined`?

```js
var obj = { key: undefined };
console.log(obj["key"] !== undefined); // false, but the key exists!
```

You should instead use the `in` operator:

```js
var obj = { key: undefined };
console.log("key" in obj); // true, regardless of the actual value
```

If you want to check if a key doesn't exist, remember to use parenthesis:

```js
var obj = { not_key: undefined };
console.log(!("key" in obj)); // true if "key" doesn't exist in object
console.log(!"key" in obj);   // Do not do this! It is equivalent to "false in obj"
```

Or, if you want to particularly test for properties of the object instance (and not inherited properties), use `hasOwnProperty`:

```js
var obj = { key: undefined };
console.log(obj.hasOwnProperty("key")); // true
```

For performance comparison between the methods that are `in`, `hasOwnProperty` and key is `undefined`, see [this **benchmark**](https://jsben.ch/WqlIl):

[![Benchmark results](https://i.stack.imgur.com/PEuZT.png)](https://i.stack.imgur.com/PEuZT.png)
If you want to check for any key at any depth on an object and account for falsey values consider this line for a utility function:

```
var keyExistsOn = (o, k) => k.split(".").reduce((a, c) => a.hasOwnProperty(c) ? a[c] || 1 : false, Object.assign({}, o)) === false ? false : true;

```

**Results**

```
var obj = {
    test: "",
    locals: {
        test: "",
        test2: false,
        test3: NaN,
        test4: 0,
        test5: undefined,
        auth: {
            user: "hw"
        }
    }
}

keyExistsOn(obj, "")
> false
keyExistsOn(obj, "locals.test")
> true
keyExistsOn(obj, "locals.test2")
> true
keyExistsOn(obj, "locals.test3")
> true
keyExistsOn(obj, "locals.test4")
> true
keyExistsOn(obj, "locals.test5")
> true
keyExistsOn(obj, "sdsdf")
false
keyExistsOn(obj, "sdsdf.rtsd")
false
keyExistsOn(obj, "sdsdf.234d")
false
keyExistsOn(obj, "2134.sdsdf.234d")
false
keyExistsOn(obj, "locals")
true
keyExistsOn(obj, "locals.")
false
keyExistsOn(obj, "locals.auth")
true
keyExistsOn(obj, "locals.autht")
false
keyExistsOn(obj, "locals.auth.")
false
keyExistsOn(obj, "locals.auth.user")
true
keyExistsOn(obj, "locals.auth.userr")
false
keyExistsOn(obj, "locals.auth.user.")
false
keyExistsOn(obj, "locals.auth.user")
true

```

Also see this NPM package: <https://www.npmjs.com/package/has-deep-value>