Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Node.js Basics 2017 Building a Command Line Application Capturing Command Line Arguments

Christopher Debove
PLUS
Christopher Debove
Courses Plus Student 18,373 Points

Could have use destructuring

In the video when we get the arguments from command line. Couldn't we not have use the destructuring?

const [,, ...users] = process.argv

in place of

const users = process.argv.slice(2);

3 Answers

Yes, but I don't think destructuring was available in Node when this video was first made.

nico dev
nico dev
20,364 Points

Elegant solution, though!

Kenneth Kim
Kenneth Kim
3,795 Points

Hi, can anyone please explain what "const [,, ...users] = process.argv" does as mention by Christopher? Is this a new syntax in ES2015? I'm not quite familiar with it yet. Thanks

Christopher Debove
Christopher Debove
Courses Plus Student 18,373 Points

Yeah it is a new syntax of ES2015.

let [a, b, c] = [1, 2, 3]; // a = 1, b = 2, c = 3
let [a,, b] = [1, 2, 3]; // a = 1, b = 3