Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

async
javascript

How to use the Dir Function in JavaScript's Async Module

Educative Answers Team

Dir

The dir function prints the result of an async function to the console using console.dir, which is compatible with Node.js and browsers that support console.dir.

console.dir behaves differently for different browsers. For instance, in Firefox, console.dir prints a navigate-able list. In Chrome, log and dir act differently with arrays.

Usage

The following example shows how the dir function may be utilized.

import dir from 'async/dir';

// Defines asynchronous function
async function asyncFunc(){
  return 'Return value';
}

// Calling dir
dir(asyncFunc);

This program shows a very basic use of dir that takes the function as a parameter. It does not show any output because the dir function uses console.dir, which only works with browsers.

RELATED TAGS

async
javascript
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring