Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • JS Tutorial
  • JS Exercise
  • JS Interview Questions
  • JS Array
  • JS String
  • JS Object
  • JS Operator
  • JS Date
  • JS Error
  • JS Projects
  • JS Set
  • JS Map
  • JS RegExp
  • JS Math
  • JS Number
  • JS Boolean
  • JS Examples
  • JS Free JS Course
  • JS A to Z Guide
  • JS Formatter
Open In App
Next Article:
Function Argument Validation in MATLAB
Next article icon

What are Arguments in a Function ?

Last Updated : 14 Feb, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Arguments in JavaScript functions are the input values passed to the function when it is called. Functions can accept zero or more arguments, which can be used within the function body to perform specific tasks or calculations.

Uses of Arguments in Functions

  • Arguments allow functions to be customized for different scenarios by passing different values.
  • Functions can be made more flexible by accepting arguments, enabling them to handle various inputs.
  • Functions with arguments promote abstraction by encapsulating functionality that can be reused with different data.

Using named parameters:

You can specify the names of parameters explicitly in the function signature, allowing flexibility in the order of arguments when calling the function.

Example: Here we are passing "Geeks for Geeks!" as an argument in the function.

JavaScript
function greet(message) {     console.log(`Hello, ${message}`); } greet("Geeks for Geeks!");  

Output
Hello, Geeks for Geeks! 

Using the arguments object:

JavaScript functions have access to an arguments object, which is an array-like object containing all the arguments passed to the function, regardless of how many arguments were specified in the function signature.

Example: Here we can access the argument property directly as it is built-in.

JavaScript
function sum() {     let total = 0;     for (let i = 0; i < arguments.length; i++) {         total += arguments[i];     }     return total; } console.log(sum(1, 2, 3)); 

Output
6 

Using default parameters:

You can specify default values for function parameters, which will be used if no argument is provided when calling the function.

Example: Here we are setting default parameter so that if we does not provide argument it still print "name".

JavaScript
function greet(name = "Geeks For Geeks") {     console.log(`Hello, ${name}!`); } greet(); greet("User"); 

Output
Hello, Geeks For Geeks! Hello, User! 

Next Article
Function Argument Validation in MATLAB

A

anjugaeu01
Improve
Article Tags :
  • JavaScript
  • Web Technologies

Similar Reads

  • Function Arguments in Programming
    Function Arguments are values or variables passed into a function when it is called. The arguments to a function play a significant role as they provide the necessary input for the function to perform its intended task. In this article, we will discuss what are Function Arguments in Programming acro
    3 min read
  • Function Argument Validation
    MATLAB is a programming language that is used for solving math problems so it is also a concept of MATLAB programming language. It is basically defined as a process to declare specific restrictions on the function arguments. By using argument validation we can constrain the class, size, and other th
    3 min read
  • Function Arguments in R Programming
    Arguments are the parameters provided to a function to perform operations in a programming language. In R programming, we can use as many arguments as we want and are separated by a comma. There is no limit on the number of arguments in a function in R. In this article, we'll discuss different ways
    4 min read
  • Function Argument Validation in MATLAB
    The basics of Function Argument is, " The functions receive certain inputs from the calling command which applies in function syntax and processes it. sometimes It may or may not produce output argument it dependence completely on the functions efficiency or the accuracy of your code." Function Argu
    5 min read
  • How to define a function in ES6 ?
    In this article, we will try to understand basic details which are associated with the function definition, like syntax declaration of a function or some examples associated with different types of functions declarations in ES6 (EcmaScript-6).  Let us first understand what exactly the function is an
    3 min read
  • PHP func_num_args() Function
    The func_num_args() function is an inbuilt function in PHP that returns the number of arguments in the user-defined function. Syntax: func_num_args(): intParameters: This function doesn't accept any parameter. Return Values: The number of arguments will be returned into the current user-defined func
    1 min read
  • function command in Linux with examples
    The function is a command in Linux that is used to create functions or methods. It is used to perform a specific task or a set of instructions. It allows users to create shortcuts for lengthy tasks making the command-line experience more efficient and convenient. The function can be created in the u
    2 min read
  • Creating Function in Files in MATLAB
    MATLAB is a high-performance language that is used for matrix manipulation, performing technical computations, graph plottings, etc. It stands for Matrix Laboratory.  Functions:The function is a set of statements or commands, which take input/s as parameters and return output. We write functions to
    2 min read
  • What is the arrow function, and how to create it ?
    Function in any programming language is the basic building block to create and combine the related bits of code. Every programming language provides certain kinds of practices to write any function. The arrow function syntax is one of the most used and efficient ones to create a function in JavaScri
    5 min read
  • What is arguments in JavaScript ?
    In this article, we will learn about arguments object in JavaScript in detail. Like what is arguments object in JavaScript and then we will discuss some programs using arguments object. We will discuss the following points: What is the arguments in JavaScript?Programs related to arguments object.The
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences