Skip to main content

Null

Pronunciation
NUL
Updated 2 min read

Share this page

Send the link, quote the definition with a link back, or show it as a card on your own site.

https://softwaredictionary.org/terms/null

In short

Null is a special value that means "no value here", used when a variable deliberately refers to no object or data at all instead of holding something real.

What is null in programming?

Null is a marker that a variable intentionally holds no value. A missing middle name, a search that found no match or a database column left empty can all be represented with null. Languages spell it differently: null in Java, JavaScript, C# and Kotlin, None in Python, nil in Ruby, Go and Swift, and NULL or nullptr in C and C++.

Null exists because variables often refer to objects, and sometimes there is no object to refer to. The trouble starts when code assumes a value is present and tries to use it: calling a method on null raises errors like Java's NullPointerException or JavaScript's TypeError: Cannot read properties of null. Tony Hoare, who introduced null references in 1965, later called them his "billion-dollar mistake" because of how many bugs and crashes they have caused.

Modern languages reduce the risk by making absence explicit in the type system. In Kotlin, Swift, strict TypeScript and C# with nullable reference types, a type such as String? or string | null must be checked before use, and the compiler complains if you forget. Rust and Haskell have no null at all and use Option or Maybe types instead. Operators such as optional chaining (user?.address) and null coalescing (name ?? "Guest") keep these checks short.

Null is often confused with other "empty" values. An empty string, the number 0 and an empty list are real values, while null means there is no value at all. JavaScript adds another neighbor, undefined, which usually means a value was never assigned, whereas null is set on purpose. In SQL, NULL means unknown, so NULL = NULL is not true and you must test with IS NULL instead.

Key takeaways

  • Null represents the deliberate absence of a value.
  • Using null as if it were a real object causes some of the most common runtime errors.
  • Kotlin, Swift, TypeScript and C# can track nullable types at compile time.
  • Rust and Haskell avoid null entirely with Option and Maybe types.
  • Null is different from empty values such as "", 0 or an empty list.

Example

Handling a nullable value in TypeScripttypescript
interface User {
  name: string;
  nickname: string | null; // may be missing on purpose
}

function displayName(user: User): string {
  // user.nickname.toUpperCase() would not compile: it might be null
  return user.nickname ?? user.name;
}

displayName({ name: "Ada", nickname: null });     // "Ada"
displayName({ name: "Grace", nickname: "Amazing" }); // "Amazing"

Readers ask

What is the difference between null and undefined in JavaScript?

undefined usually means a variable or property was never given a value, while null is assigned deliberately to mean "no value". null == undefined is true, but null === undefined is false because they are different types.

What is a null pointer exception?

It's the error raised when code tries to use a null reference as if it pointed to a real object, for example by calling a method on it. Java calls it NullPointerException, and other languages have similar errors under different names.

Why is null called the billion-dollar mistake?

Computer scientist Tony Hoare, who added null references to the ALGOL W language in 1965, used that phrase in 2009 to describe the huge cost of the crashes and bugs null has caused. Many newer languages therefore require missing values to be handled explicitly.

See also

Spotted a mistake or something missing on this page?Suggest an edit

Read a random page
Open today's review
Switch to the dark theme
Read this page in Türkçe

More

Settings