Using rest and spread operators in JavaScript