Skip to content

Clarify setTimeout return value in timers documentation (Node.js returns a Timeout object, not just an ID) #7672

Open
@ShubhamOulkar

Description

@ShubhamOulkar

Doc URL(s)

https://nodejs.org/en/learn/asynchronous-work/discover-javascript-timers

Description of the problem

In Node.js, setTimeout() and setInterval() returns a Timeout object, which can be used to cancel or manipulate the timer. In browsers, it returns a numeric timer ID. The current Node.js documentation says these functions return a "timer ID", which can be misleading in the Node context.

Docs should reflect Node-specific behavior more precisely

  1. Browser devs might expect a number and be confused when console.log(setTimeout(...)) gives them an object.
  2. They might not realize unref() and other methods are available.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    📋 Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions