QamoosTech
Programming FundamentalsLanguage basicsBeginnerJavaScript

Null vs Undefined

PronunciationNUL versos UN-de-fined

Definition

null represents an intentional absence of any object value, while undefined means a variable has been declared but not yet assigned a value.

Where you hear it

During code reviews, debugging missing data, or checking API response payloads in JavaScript and TypeScript.

Examples

  • Declaring a variable without a value automatically sets its state to undefined.
  • Developers explicitly assign null to clear a variable or indicate a missing resource.
  • The API returns null when the user has no middle name, to show the field was left empty on purpose.

Common mistake

Treating them as completely interchangeable, leading to unexpected type errors when checking optional properties.

Say it at work

  • In a meeting or chatLet's check if the user profile is null or undefined before we render the avatar.
  • In an email or ticketPlease ensure the function handles both null and undefined parameters correctly to prevent runtime errors.