JavaScript Academy · Lesson

Truthy and Falsy Values

Know which values evaluate as true or false.

Lesson 1 of 413 steps

Truthy and Falsy Values is a free JavaScript Academy lesson on CoddyKit. This is lesson 1 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the JavaScript Academy learning path, and your progress syncs across the web and the CoddyKit app. The JavaScript Academy course includes 4 lessons in total.

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))
Free to start

Learn JavaScript with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
59
Lessons
200

Frequently Asked Questions

Is the “Truthy and Falsy Values” lesson free?

Yes — any 3 lessons of the JavaScript Academy learning path, including “Truthy and Falsy Values”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The JavaScript Academy course includes 4 lessons in total.

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, so you can start here or from the beginning and move at your own pace. This is lesson 1 of 4.

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