Skip to content

Incorrect explanation of nullish coalescing operator in lesson #63409

Closed

Description

@l3onhard

Describe the Issue

The lesson "What Are Binary Logical Operators, and How Do They Work?" incorrectly explains that the nullish coalescing operator (??) works with falsy values, when it actually only works with nullish values (null and undefined):

Here is an example of working with the nullish coalescing operator:

const result = null ?? 'default';
console.log(result); // default

Since null is a falsy value, the string default would be logged to the console.

However, the nullish coalescing operator (??) does not check for falsy values.

According to MDN: The nullish coalescing (??) operator is a logical operator that returns its right-hand side operand when its left-hand side operand is null or undefined, and otherwise returns its left-hand side operand.

Affected Page

https://www.freecodecamp.org/learn/full-stack-developer/lecture-working-with-conditional-logic-and-math-methods/what-are-binary-logical-operators-and-how-do-they-work

Your code

// Nullish coalescing (??) - only checks for null/undefined
console.log(0 ?? 'default');        // 0 (not 'default')
console.log('' ?? 'default');       // '' (not 'default')
console.log(false ?? 'default');    // false (not 'default')
console.log(null ?? 'default');     // 'default'
console.log(undefined ?? 'default'); // 'default'

// OR operator (||) - checks for ALL falsy values
console.log(0 || 'default');        // 'default'
console.log('' || 'default');       // 'default'
console.log(false || 'default');    // 'default'
console.log(null || 'default');     // 'default'
console.log(undefined || 'default'); // 'default'

Expected behavior

Here is an example of working with the nullish coalescing operator:

const result = null ?? 'default';
console.log(result); // default

Since null is a nullish value (either null or undefined), the nullish coalescing operator returns the right-hand operand, and the string default would be logged to the console.

Screenshots

No response

System

n/a

Additional context

No response

Activity

  1. added
    scope: curriculum
    status: waiting triage
    on Oct 31, 2025
  2. garyeung commented on Nov 1, 2025

    @garyeung
    Contributor

    Represented by a double question mark (??), it helps in scenarios where you want to return a value only if the first one is null or undefined.

    I think the course is explained very clearly.

  3. majestic-owl448 commented on Nov 1, 2025

    @majestic-owl448
    Contributor

    the only sentence that seem to be updating is

    Since null is a falsy value, the string default would be logged to the console.

    it should be "Since null is a nullish value, the string default would be logged to the console."

    or there are other issues that I am not noticing? The explanation above the example seems fine

  4. l3onhard commented on Nov 1, 2025

    @l3onhard
    ContributorAuthor

    Yes, I meant to say that only the sentence Since null is a falsy value[...] needs correction.

  5. added
    help wanted
    and removed
    status: waiting triage
    on Nov 2, 2025
  6. shashankdangi commented on Nov 2, 2025

    @shashankdangi
    Contributor

    Can i work on it ? or is it still in discussion ?

  7. majestic-owl448 commented on Nov 2, 2025

    @majestic-owl448
    Contributor

    @shashankdangi when an issue has the help wanted label it means it is open for contributors to work on

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedscope: curriculum

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions