0Pricing
JavaScript Academy · Lesson

Truthy and Falsy Values

Know which values evaluate as true or false.

Truthy and Falsy Values is a free JavaScript Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the JavaScript Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Truthy and Falsy

In a boolean context such as an if statement, every JavaScript value is treated as either truthy or falsy. Falsy values behave like false; everything else is truthy.

if ("hello") {
  console.log("strings are truthy")
}

The Falsy List

There are exactly eight falsy values. Memorize them, because everything not on the list is truthy.

  • false
  • 0 and negative zero
  • empty string
  • null
  • undefined
  • NaN
  • BigInt zero
console.log(Boolean(0))
console.log(Boolean(""))
console.log(Boolean(null))

Zero Is Falsy

The number zero is falsy, but any other number, including negative numbers, is truthy.

console.log(Boolean(0))
console.log(Boolean(-5))
console.log(Boolean(0.1))

Empty String Is Falsy

An empty string is falsy, but a string containing a space or the text false is truthy because it is not empty.

console.log(Boolean(""))
console.log(Boolean(" "))
console.log(Boolean("false"))

Null and Undefined

Both null and undefined are falsy. They represent the absence of a value.

console.log(Boolean(null))
console.log(Boolean(undefined))

NaN Is Falsy

NaN, the result of an invalid numeric operation, is falsy. This catches failed conversions in boolean checks.

console.log(Boolean(NaN))
console.log(Boolean(Number("abc")))

Objects Are Always Truthy

Every object and array is truthy, even an empty one. This surprises many developers who expect an empty array to be falsy.

console.log(Boolean({}))
console.log(Boolean([]))

Coercing to Boolean

The double-not operator is a concise way to convert any value to its boolean equivalent, mirroring what an if statement does.

console.log(!!"text")
console.log(!!0)
console.log(!![])

Using Truthiness in Conditions

You often rely on truthiness to check for missing values. An empty string, null, or undefined will all skip the if branch.

function greet(name) {
  if (name) {
    return "Hi " + name
  }
  return "Hi guest"
}
console.log(greet(""))
console.log(greet("Ann"))

Default Values With Or

The logical OR operator returns the first truthy operand, a classic way to supply defaults. Beware that zero and empty string trigger the default.

const input = ""
const value = input || "default"
console.log(value)

Nullish Versus Falsy

The nullish coalescing operator only falls back for null or undefined, not for other falsy values like zero, which makes it safer for numeric defaults.

const count = 0
console.log(count || 10)
console.log(count ?? 10)

Quick Check

Test your truthy and falsy knowledge.

Recap

Recap: Eight falsy values exist; everything else is truthy.

  • Falsy: false, 0, empty string, null, undefined, NaN, BigInt zero
  • Empty objects and arrays are truthy
  • Double-not converts to boolean
  • Nullish coalescing only checks null and undefined
console.log(Boolean([]))
console.log(Boolean(0))

Frequently asked questions

Is the “Truthy and Falsy Values” lesson free?

Yes — the full text of “Truthy and Falsy Values” is free to read here on the web, and the JavaScript Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the JavaScript Academy course, upgrade to CoddyKit PRO.

What will I learn in “Truthy and Falsy Values”?

Know which values evaluate as true or false. You practise JavaScript Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start JavaScript Academy?

No prior experience is required. JavaScript Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Truthy and Falsy Values” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this JavaScript Academy lesson?

Yes. Every JavaScript Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Truthy and Falsy Values
  2. Loose vs Strict Equality
  3. Implicit Coercion in Operations
  4. Explicit Conversion Techniques
← Back to JavaScript Academy