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: 
**Answer:**

```
if ("key" in myObj)
{
    console.log("key exists!");
}
else
{
    console.log("key doesn't exist!");
}

```

**Explanation:**

The `in` operator will check if the key exists in the object. If you checked if the value was undefined: `if (myObj["key"] === 'undefined')`, you could run into problems because a key could possibly exist in your object with the `undefined` value.

For that reason, it is much better practice to first use the `in` operator and then compare the value that is inside the key once you already know it exists.
**JS Double Exclamation `!!` sign may help in this case.**

```
const cars = {
        petrol:{
            price: 5000
        },
        gas:{
            price:8000
        }
    }

```

Suppose we have the object above and If you try to log car with petrol price.

```
=> console.log(cars.petrol.price);
=> 5000

```

> 
> You'll definitely get 5000 out of it. But what if you try to get an
> electric car which does not exist then you'll get `undefine`
> 
> 
> 

```
=> console.log(cars.electric);
=> undefine

```

> 
> But using `!!` which is its short way to cast a variable to be a
> Boolean (true or false) value.
> 
> 
> 

```
=> console.log(!!cars.electric);
=> false

```