Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. JavaScript Course

Lesson 21 of 55 · javascript

Spread & Rest Syntax

Duration: 7 mins

Spread expands an iterable into individual elements.

const a = [1,2];
const b = [...a,3,4]; // [1,2,3,4]

Rest gathers remaining elements into an array.

function sum(...nums){ return nums.reduce((a,b)=>a+b,0); }

Works with objects as well.

const obj1 = {a:1};
const obj2 = {...obj1, b:2}; // {a:1,b:2}
Previous: Object Literals, Shorthand & DestructuringNext: Classes – ES6 Syntax, Inheritance, Getters/Setters, static