2

I came across this while learning about child processes:

const {spawn} = require('child_process');

My question is, what is the difference between the above and this:

const spawn = require('child_process');
fedesc
  • 2,554
  • 2
  • 23
  • 39
Tejas_hooray
  • 606
  • 1
  • 6
  • 16

1 Answers1

0

The 1st extracts spawn variable from inside child_proccess. This only unpack value of spawn from child_proccess instead of the whole module.

The 2nd sets spawn variable the entire child_process module (as a whole).

read more on Destructuring assignment

fedesc
  • 2,554
  • 2
  • 23
  • 39