Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
Question 3 of 10 · Functions and Arrow Functions
Interview question

What is the difference between parameters and arguments? Parameters और arguments में क्या अंतर है?

Answer
TermMeaningExample
ParametersVariables listed in function definitionfunction test(a, b) { } - a, b are parameters
ArgumentsActual values passed when calling the functiontest(1, 2) - 1, 2 are arguments
// Parameters are defined in the function signature
function greet(name, age) {  // name, age = parameters
    console.log(`Hello ${name}, you are ${age}`);
}

// Arguments are passed when calling
greet('John', 30);  // 'John', 30 = arguments

// More arguments than parameters
greet('Jane', 25, 'Extra argument');
// The extra argument is ignored (unless using rest parameters)

// Fewer arguments than parameters
greet('Bob');
// age will be undefined

// Using the arguments object (only in regular functions)
function test() {
    console.log(arguments); // [1, 2, 3]
    console.log(arguments[0]); // 1
    console.log(arguments.length); // 3
}
test(1, 2, 3);

// Arrow functions don't have arguments object
const arrow = () => {
    console.log(arguments); // ReferenceError: arguments is not defined
};

Interview tip: Explain that you can pass any number of arguments to a function in JavaScript, even if the number of parameters doesn't match. Use rest parameters (...args) to capture excess arguments.

TermMeaningExample
ParametersFunction definition में variablesfunction test(a, b) { } - a, b parameters
ArgumentsFunction call करते समय pass किए गए actual valuestest(1, 2) - 1, 2 arguments
// Parameters function signature में define होते हैं
function greet(name, age) {  // name, age = parameters
    console.log(`Hello ${name}, you are ${age}`);
}

// Arguments call करते समय pass होते हैं
greet('John', 30);  // 'John', 30 = arguments

// Parameters से ज़्यादा arguments
greet('Jane', 25, 'Extra');
// Extra argument ignore हो जाता है

// Parameters से कम arguments
greet('Bob');
// age = undefined

// arguments object (regular functions में)
function test() {
    console.log(arguments); // [1, 2, 3]
    console.log(arguments[0]); // 1
}
test(1, 2, 3);

// Arrow functions में arguments नहीं
const arrow = () => {
    console.log(arguments); // ReferenceError
};

इंटरव्यू टिप: समझाएं JavaScript में आप function को कितने भी arguments pass कर सकते हैं, चाहे parameters की संख्या match न हो। Excess arguments को capture करने के लिए rest parameters (...args) use करें।

Was this answer clear?