Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    What's Hot

    A New Dawn: Navi Mumbai International Airport

    October 10, 2025

    The Most Important Innovation in Travel Since Airplanes: Japanese Genius Creates AI Instant Translator

    October 7, 2025

    A New Beginning: How GST 2.0 Is Changing Everyday Life

    October 6, 2025
    Facebook Twitter Instagram
    • Home
    • Features
      • Example Post
      • Typography
      • Contact
      • View All On Demos
    • Technology

      AI in India Careers: Why You Must Upgrade Skills Now

      August 27, 2025

      Agentic AI in 2025: Navigating the Future of Autonomous Digital Assistants

      August 18, 2025

      From Syntax to Prompts: What to Learn in Coding in 2025

      August 14, 2025

      Best Programming Language to Learn in 2025 – A Beginner’s Roadmap

      August 7, 2025

      Smart Factories: How AI and IoT Are Powering Industry 4.0

      August 5, 2025
    • Typography
    • Phones
      1. Technology
      2. Gaming
      3. Gadgets
      4. View All

      AI in India Careers: Why You Must Upgrade Skills Now

      August 27, 2025

      Agentic AI in 2025: Navigating the Future of Autonomous Digital Assistants

      August 18, 2025

      From Syntax to Prompts: What to Learn in Coding in 2025

      August 14, 2025

      Best Programming Language to Learn in 2025 – A Beginner’s Roadmap

      August 7, 2025

      A Clash for the Ages: India vs Pakistan – 28 September 2025

      September 30, 2025

      Olympics 2025: The Top Athletes and Tech Behind the Game

      August 6, 2025

      Retro Gaming Comeback: Why Old Is Gold Again

      June 4, 2025

      Game On, Bags Packed: How Video Games Are Shaping Gen Z Travel in 2025

      June 4, 2025

      Using AR/VR in Mental Health Therapy: Is It Effective?

      July 14, 2025

      Samsung Galaxy Z Fold7: The Future of Foldables Is Here

      July 10, 2025

      Are Smart Glasses the Next Smartphone? Here’s What 2025 Tells Us

      July 4, 2025

      Compact Yet Mighty: OnePlus 13s Launches with Snapdragon 8 Elite

      June 6, 2025

      Clash of Titans: Samsung Galaxy Fold vs iPhone 16 Pro — Which One Reigns Supreme?

      October 1, 2025

      Compact Yet Mighty: OnePlus 13s Launches with Snapdragon 8 Elite

      June 6, 2025

      Find Your Lost Android Phone: A Simple Guide

      December 29, 2023

      Instagram Ads: Run Your First Ad Campaign in Just 5 Easy Steps

      December 5, 2023
    Facebook Twitter Instagram Pinterest Vimeo
    Zarsco Blogs🚀Zarsco Blogs🚀
    • Home
    • Features
      • Example Post
      • Typography
      • Contact
      • View All On Demos
    • Technology

      AI in India Careers: Why You Must Upgrade Skills Now

      August 27, 2025

      Agentic AI in 2025: Navigating the Future of Autonomous Digital Assistants

      August 18, 2025

      From Syntax to Prompts: What to Learn in Coding in 2025

      August 14, 2025

      Best Programming Language to Learn in 2025 – A Beginner’s Roadmap

      August 7, 2025

      Smart Factories: How AI and IoT Are Powering Industry 4.0

      August 5, 2025
    • Typography
    • Phones
      1. Technology
      2. Gaming
      3. Gadgets
      4. View All

      AI in India Careers: Why You Must Upgrade Skills Now

      August 27, 2025

      Agentic AI in 2025: Navigating the Future of Autonomous Digital Assistants

      August 18, 2025

      From Syntax to Prompts: What to Learn in Coding in 2025

      August 14, 2025

      Best Programming Language to Learn in 2025 – A Beginner’s Roadmap

      August 7, 2025

      A Clash for the Ages: India vs Pakistan – 28 September 2025

      September 30, 2025

      Olympics 2025: The Top Athletes and Tech Behind the Game

      August 6, 2025

      Retro Gaming Comeback: Why Old Is Gold Again

      June 4, 2025

      Game On, Bags Packed: How Video Games Are Shaping Gen Z Travel in 2025

      June 4, 2025

      Using AR/VR in Mental Health Therapy: Is It Effective?

      July 14, 2025

      Samsung Galaxy Z Fold7: The Future of Foldables Is Here

      July 10, 2025

      Are Smart Glasses the Next Smartphone? Here’s What 2025 Tells Us

      July 4, 2025

      Compact Yet Mighty: OnePlus 13s Launches with Snapdragon 8 Elite

      June 6, 2025

      Clash of Titans: Samsung Galaxy Fold vs iPhone 16 Pro — Which One Reigns Supreme?

      October 1, 2025

      Compact Yet Mighty: OnePlus 13s Launches with Snapdragon 8 Elite

      June 6, 2025

      Find Your Lost Android Phone: A Simple Guide

      December 29, 2023

      Instagram Ads: Run Your First Ad Campaign in Just 5 Easy Steps

      December 5, 2023
    Subscribe
    Zarsco Blogs🚀Zarsco Blogs🚀
    Home » All about JavaScript Operators
    Featured

    All about JavaScript Operators

    Abdul RehmanBy Abdul RehmanApril 12, 2023Updated:April 12, 2023No Comments5 Mins Read
    Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
    Share
    Facebook Twitter LinkedIn Pinterest Email

    What are Rest and Spread Operators ?

    JavaScript uses three dots (...) for both the rest and spread operators. But these two operators are not the same.

    Difference :- The main difference between rest and spread is that the rest operator puts the rest of some specific user-supplied values into a JavaScript array. But the spread syntax expands iterables into individual elements.

    Here’s an example :

    // Define a function with three parameters:
    function myBio(firstName, lastName, company) { 
      return `${firstName} ${lastName} runs ${company}`;
    }
    
    // Use spread to expand an array’s items into individual arguments:
    myBio(...["Abdul Rehman", "Khams", "Zarsco"]);
    
    // The invocation above will return:
    “Abdul Rehman Khams runs Zarsco”

    In the snippet above, we used the spread operator (...) to spread ["Abdul Rehman, "Khams", "Zarsco"]’s content across myBio()’s parameters.

    Don’t worry if you don’t understand the rest or spread operators yet. This article has got you covered!

    In the following sections, we will discuss how rest and spread work in JavaScript.

    So, without wasting any time let’s get started with the rest operator.

    Detailed Explanation on Rest Operator

    The rest operator is used to put the rest of some specific user-supplied values into a JavaScript array.

    So, for instance, here is the rest syntax:

    ...yourValues

    The three dots (...) in the snippet above symbolize the rest operator.

    The text after the rest operator references the values you wish to encase inside an array. You can only use it before the last parameter in a function definition.

    To understand the syntax better, let’s see how rest works with JavaScript functions.

    Working Of Rest Operator

    In JavaScript functions, rest gets used as a prefix of the function’s last parameter.

    Here’s an example:

    // Define a function with two regular parameters and one rest parameter:
    function myBio(firstName, lastName, ...otherInfo) { 
      return otherInfo;
    }

    The rest operator (...) instructs the computer to add whatever otherInfo (arguments) supplied by the user into an array. Then, assign that array to the otherInfo parameter.

    As such, we call ...otherInfo a rest parameter.

    Note: Arguments are optional values you may pass to a function’s parameter through an invocator. Also you cannot use “use strict” inside a function using Rest Operator.

     

    How Rest Operator works on Destructing Assignments

     

    The rest operator typically gets used as a prefix of the destructuring assignment’s last variable.

    Here’s an example:

    // Define a destructuring array with two regular variables and one rest variable:
    const [firstName, lastName, ...otherInfo] = [
      "Abdul Rehman", "Khams", "Zarsco", "Web Developer", "Male"
    ];
    
    // Invoke the otherInfo variable:
    console.log(otherInfo); 
    
    // The invocation above will return:
    ["Zarsco", "Web Developer", "Male"]

     

    The rest operator (...) instructs the computer to add the rest of the user-supplied values into an array. Then, it assigns that array to the otherInfo variable.

    As such, you may call ...otherInfo a rest variable.

    Here’s another example:

    // Define a destructuring object with two regular variables and one rest variable:
    const { firstName, lastName, ...otherInfo } = {
      firstName: "Abdul Rehman",
      lastName: "Khams", 
      companyName: "Zasco",
      profession: "Web Developer",
      gender: "Male"
    }
    
    // Invoke the otherInfo variable:
    console.log(otherInfo);
    
    // The invocation above will return:
    {companyName: "Zarsco", profession: "Web Developer", gender: "Male"}

     

    In the snippet above, notice that the rest operator assigned a properties object — not an array — to the otherInfo variable.

    In other words, whenever you use rest in a destructuring object, the rest operator will produce a properties object.

    However, if you use rest in a destructuring array or function, the operator will yield an array literal.

     

    Detailed Explanation on Spread Operator

     

    The spread operator (...) helps you expand iterables into individual elements.

    The spread syntax works within array literals, function calls, and initialized property objects to spread the values of iterable objects into separate items. So effectively, it does the opposite thing from the rest operator.

    Note: A spread operator is effective only when used within array literals, function calls, or initialized properties objects.

    So, what exactly does this mean? Let’s see with some examples.

     

    Example 1 :-  How Spread Works in an Array Literal

     

    const myName = ["Abdul Rehman", "is", "my"];
    const aboutMe = ["Khams", ...myName, "name."];
    
    console.log(aboutMe);
    
    // The invocation above will return:
    [ "Khams", "Abdul Rehman", "is", "my", "name." ]

     

    The snippet above used spread (...) to copy the myName array into aboutMe.

     

    Example 2 :- How to Use Spread to Convert a String into Individual Array Items

     

    const myName = "Khams Abdul Rehman";
    
    console.log([...myName]);
    
    // The invocation above will return:
    [ "K", "h", "a", "m", "s", "A", "b", "d", "u", "l"," ", "R", "e", "h", "m", "a", "n" ]

     

    In the snippet above, we used the spread syntax (...) within an array literal object ([...]) to expand myName’s string value into individual items.

    As such, "Khams Abdul Rehman" got expanded into [ "K", "h", "a", "m", "s", "A", "b", "d", "u", "l"," ", "R", "e", "h", "m", "a", "n" ].

     

    What to know about Spread Operators 

    1. Spread operators can’t expand object literal’s values

    2. The spread operator does not clone identical properties

    3. Beware of how spread works when used on objects containing non-primitives!

    Hope this post proved helpful to you , please comment it down if you want more like this.

    JavaScript Operators Rest Operator Spread Operator
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleExploring the Creative Potential of AI
    Next Article How to start your business :- 10 easy and important steps
    Abdul Rehman
    • Facebook
    • Instagram

    Related Posts

    Featured

    Nepal Gen Z Protests: Corruption and Nepotism Fuel Youth Anger

    September 10, 2025
    Featured

    Korean Cuisine in India: A Growing Trend Among Gen Z and Millennials

    August 25, 2025
    Featured

    August 2025’s Night Sky Will Sparkle with 100,000 Stars at Once

    August 25, 2025
    Add A Comment

    Leave A Reply Cancel Reply

    Demo
    Top Posts

    The Future of Artificial Intelligence: Trends and Predictions

    August 7, 2023136 Views

    Love: A Journey of Endless Emotions

    August 7, 2023108 Views

    Some important questions related to E-Commerce

    January 22, 202398 Views
    Stay In Touch
    • Facebook
    • YouTube
    • TikTok
    • WhatsApp
    • Twitter
    • Instagram
    Latest Reviews
    85
    Featured

    Pico 4 Review: Should You Actually Buy One Instead Of Quest 2?

    mrzulfJanuary 15, 2021
    8.1
    Uncategorized

    A Review of the Venus Optics Argus 18mm f/0.95 MFT APO Lens

    mrzulfJanuary 15, 2021
    8.9
    Editor's Picks

    DJI Avata Review: Immersive FPV Flying For Drone Enthusiasts

    mrzulfJanuary 15, 2021

    Subscribe to Updates

    Get the latest tech news from FooBar about tech, design and biz.

    Demo
    Most Popular

    The Future of Artificial Intelligence: Trends and Predictions

    August 7, 2023136 Views

    Love: A Journey of Endless Emotions

    August 7, 2023108 Views

    Some important questions related to E-Commerce

    January 22, 202398 Views
    Our Picks

    A New Dawn: Navi Mumbai International Airport

    October 10, 2025

    The Most Important Innovation in Travel Since Airplanes: Japanese Genius Creates AI Instant Translator

    October 7, 2025

    A New Beginning: How GST 2.0 Is Changing Everyday Life

    October 6, 2025

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    Facebook Twitter Instagram Pinterest
    © 2025 Zasrco Blogs. Designed by Zarsco.

    Type above and press Enter to search. Press Esc to cancel.