Subscribe to Updates

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

    What's Hot

    Best Side Hustles You Can Start from Home in 2025 – For Students

    June 13, 2025

    COVID-19 Surge in India 2025: Rising Cases and Precautionary Measures

    June 13, 2025

    How Samsung Engineered the Galaxy S25 Edge To Break Boundaries

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

      The Rise of AI Stylists: How Smart Mirrors Are Picking Your Outfits

      June 11, 2025

      AI-Powered Programming: How Human Language is Revolutionizing Coding

      June 10, 2025

      Unlocking Creativity: How to Use ChatGPT-5 and Sora Creatively

      June 3, 2025

      The Rise of AI-Powered Personal Assistants in 2025: What to Expect

      June 3, 2025

      Future of Robotics: Who’s Leading the Race in 2025?

      May 31, 2025
    • Typography
    • Phones
      1. Technology
      2. Gaming
      3. Gadgets
      4. View All

      The Rise of AI Stylists: How Smart Mirrors Are Picking Your Outfits

      June 11, 2025

      AI-Powered Programming: How Human Language is Revolutionizing Coding

      June 10, 2025

      Unlocking Creativity: How to Use ChatGPT-5 and Sora Creatively

      June 3, 2025

      The Rise of AI-Powered Personal Assistants in 2025: What to Expect

      June 3, 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

      The Metaverse: A New Frontier in Virtual Reality

      April 11, 2023

      Exploring the World of AR/VR Technology

      April 8, 2023

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

      June 6, 2025

      The Rise of AI-Powered Personal Assistants in 2025: What to Expect

      June 3, 2025

      Wearable Tech 2.0: What’s Hot This Year?

      May 27, 2025

      OpenAI’s Sora: A Glimpse into the Future of Video Creation?

      February 17, 2024

      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

      The Most Radiation Emitting Phones of 2023 You Need To Know

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

      The Rise of AI Stylists: How Smart Mirrors Are Picking Your Outfits

      June 11, 2025

      AI-Powered Programming: How Human Language is Revolutionizing Coding

      June 10, 2025

      Unlocking Creativity: How to Use ChatGPT-5 and Sora Creatively

      June 3, 2025

      The Rise of AI-Powered Personal Assistants in 2025: What to Expect

      June 3, 2025

      Future of Robotics: Who’s Leading the Race in 2025?

      May 31, 2025
    • Typography
    • Phones
      1. Technology
      2. Gaming
      3. Gadgets
      4. View All

      The Rise of AI Stylists: How Smart Mirrors Are Picking Your Outfits

      June 11, 2025

      AI-Powered Programming: How Human Language is Revolutionizing Coding

      June 10, 2025

      Unlocking Creativity: How to Use ChatGPT-5 and Sora Creatively

      June 3, 2025

      The Rise of AI-Powered Personal Assistants in 2025: What to Expect

      June 3, 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

      The Metaverse: A New Frontier in Virtual Reality

      April 11, 2023

      Exploring the World of AR/VR Technology

      April 8, 2023

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

      June 6, 2025

      The Rise of AI-Powered Personal Assistants in 2025: What to Expect

      June 3, 2025

      Wearable Tech 2.0: What’s Hot This Year?

      May 27, 2025

      OpenAI’s Sora: A Glimpse into the Future of Video Creation?

      February 17, 2024

      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

      The Most Radiation Emitting Phones of 2023 You Need To Know

      December 4, 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

    Best Side Hustles You Can Start from Home in 2025 – For Students

    June 13, 2025
    Featured

    COVID-19 Surge in India 2025: Rising Cases and Precautionary Measures

    June 13, 2025
    Featured

    Shubhanshu Shukla: India’s Next Space Hero Prepares for Historic ISS Mission

    June 11, 2025
    Add A Comment

    Leave A Reply Cancel Reply

    Demo
    Top Posts

    The Future of Artificial Intelligence: Trends and Predictions

    August 7, 2023134 Views

    Love: A Journey of Endless Emotions

    August 7, 2023106 Views

    Some important questions related to E-Commerce

    January 22, 202397 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, 2023134 Views

    Love: A Journey of Endless Emotions

    August 7, 2023106 Views

    Some important questions related to E-Commerce

    January 22, 202397 Views
    Our Picks

    Best Side Hustles You Can Start from Home in 2025 – For Students

    June 13, 2025

    COVID-19 Surge in India 2025: Rising Cases and Precautionary Measures

    June 13, 2025

    How Samsung Engineered the Galaxy S25 Edge To Break Boundaries

    June 13, 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.