Null Pointer Exception
ELI5 — The Vibe Check
A null pointer exception (NPE) is what happens when your code tries to use something that doesn't exist — like calling a method on null. Tony Hoare, who invented null, called it his 'billion dollar mistake' because NPEs have probably caused more crashes than any other single bug type. Modern languages fight back with optionals, null safety, and the almighty question mark operator (?.).
Real Talk
A null pointer exception (NPE/NullPointerException/TypeError: Cannot read property of null) occurs when code attempts to dereference a null or undefined reference. It's historically the most common runtime error. Modern language features combat it: Kotlin's null safety, TypeScript's strict null checks, Rust's Option type, and JavaScript's optional chaining (?.) operator.
Show Me The Code
// JavaScript: the classic NPE
const user = null
console.log(user.name) // TypeError: Cannot read property 'name' of null
// The fix: optional chaining
console.log(user?.name) // undefined (no crash)
// TypeScript strict null checks prevent this at compile time
function greet(user: User | null) {
// TypeScript error: 'user' is possibly null
console.log(user.name) // Caught at compile time!
}
When You'll Hear This
"The billion dollar mistake strikes again — null pointer exception in production." / "Enable strict null checks in TypeScript. Seriously. Do it now."
Related Terms
Error Handling
Error handling is the art of planning for things to go wrong and dealing with them gracefully instead of letting everything catch fire.
Null
Null means 'intentionally nothing' — a programmer chose to say 'there is no value here'. It is a deliberate absence.
Option Type
Option type is the type system's way of saying 'this might have a value, or it might be empty, and you MUST handle both cases.
TypeScript
TypeScript is JavaScript with a strict parent watching over it.
Undefined
Undefined in JavaScript means a variable exists but has never been given a value.