# Is
{: .no_toc }

Used to compare two object references for identity.

Syntax:
> *result* **=** *object1* **Is** *object2*

*result*
: Any **Boolean** or numeric variable.

*object1*, *object2*
: Any object references.

If *object1* and *object2* both refer to the same object, *result* is **True**; if they don't, *result* is **False**. **Is** does not compare values inside the objects --- it compares whether the two references point to the same instance.

Two variables can be made to refer to the same object in several ways. In the following example, A has been set to refer to the same object as B:

```tb check_build
Dim A As Object, B As Object
Set A = B
```

The following example makes A and B refer to the same object as C:

```tb check_build
Dim A As Object, B As Object, C As Object
Set A = C
Set B = C
```

A reference compared against **Nothing** with **Is** tells whether the reference is unassigned:

```tb check_build
Dim MyObject As Object
If MyObject Is Nothing Then
    Debug.Print "MyObject has not been assigned."
End If
```

For the negation of an identity test, twinBASIC also provides the [**IsNot**](/tB/Core/IsNot.md) operator: `If MyObject IsNot Nothing Then` reads more naturally than `If Not (MyObject Is Nothing) Then`.

> [!NOTE]
> The **Is** keyword has two unrelated uses elsewhere in the language:
>
> - In an **[If...Then...Else](/tB/Core/If-Then-Else.md)** condition of the form **TypeOf** *objectname* **Is** *objecttype*, **Is** introduces a runtime type test.
> - In a **[Select Case](/tB/Core/Select-Case.md)** clause of the form **Is** *comparisonoperator* *expression*, **Is** introduces a comparison against the **Select Case** test expression.
>
> In both of those constructs the surrounding statement provides the meaning; **Is** there is not the object-identity operator described on this page.

### Example

This example uses the **Is** operator to compare two object references.

```tb check_build
Dim MyObject, YourObject, ThisObject, OtherObject, ThatObject, MyCheck
Set YourObject = MyObject    ' Assign object references.
Set ThisObject = MyObject
Set ThatObject = OtherObject
MyCheck = YourObject Is ThisObject    ' Returns True.
MyCheck = ThatObject Is ThisObject    ' Returns False.
' Assume MyObject <> OtherObject.
MyCheck = MyObject Is ThatObject    ' Returns False.
```

### See Also

- [**IsNot** operator](/tB/Core/IsNot.md)
- [**Set** statement](/tB/Core/Set.md)
- [**If...Then...Else** statement](/tB/Core/If-Then-Else.md)
- [**Select Case** statement](/tB/Core/Select-Case.md)
