Skip to content
This repository was archived by the owner on Jan 25, 2022. It is now read-only.
This repository was archived by the owner on Jan 25, 2022. It is now read-only.

How does Nil affect non optional function calls  #2

@xtuc

Description

@xtuc

Initial discussion from Babel's Slack

From claudepache/es-optional-chaining:

Technically the semantics are enforced by introducing a special Reference, called Nil, which is propagated without further evaluation through left-hand side expressions (property accesses, method calls, etc.), and which dereferences to undefined (or to /dev/null in write context).

In this example what would be the ouput if b is null?

a?.b()

I expect this to throw but as far as I understand Nil will be propagated and b will not be called.

a?.b?.()

In the latter case we're using the optional chaining syntax so that the function call b() is conditional

What is the difference between the two examples?
What do you think about that?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions