---
title: Don't explicitly initialize variables to null
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Datadog Security > Code Security > Static Code Analysis (SAST) > SAST
  Rules > Don't explicitly initialize variables to null
---

> For the complete documentation index, see [llms.txt](https://docs.datadoghq.com/llms.txt).

# Don't explicitly initialize variables to null

{% callout %}
# Important note for users on the following Datadog sites: app.ddog-gov.com, us2.ddog-gov.com

{% alert level="danger" %}
This product is not supported for your selected [Datadog site](https://docs.datadoghq.com/getting_started/site.md). ({% placeholder "user-datadog-site-name" /%}).
{% /alert %}

{% /callout %}

## Metadata{% #metadata %}

**ID:** `dart-code-quality/avoid-init-to-null`

**Language:** Dart

**Severity:** Notice

**Category:** Code Style

## Description{% #description %}

If a variable has a non-nullable type or is final, Dart reports a compile error if you try to use it before it has been definitely initialized. If the variable is nullable and not const or final, then it is implicitly initialized to null for you. There's no concept of "uninitialized memory" in Dart and no need to explicitly initialize a variable to null to be "safe". Adding = null is redundant and unneeded.

## Non-Compliant Code Examples{% #non-compliant-code-examples %}

```dart
int? a = null;
String? b = null;

Item? bestDeal(List<Item> cart) {
  Item? bestItem = null;
  return bestItem;
}
```

## Compliant Code Examples{% #compliant-code-examples %}

```dart
int? a;
String? b;
bool? c;
```
  Seamless integrations. Try Datadog Code SecurityDatadog Code Security 
{% icon name="icon-external-link" /%}
 